ITPEC FE Subject B April 2026 Question 16

From the answer group below, select the correct answer to be inserted into blank in the program. The same answer goes into both blanks blank. Here, the array index starts at 1.

The program converts the code point of a Unicode character to a 2-byte UTF-8 encoding. In this question, “(16)” after a numerical value indicates a hexadecimal value. Each Unicode character is given an integer value that is known as a code point. A character with a code point that ranges from 80(16) to 7FF(16) is encoded to a 2-byte value as below.

Let the bit pattern with a 2-byte length be: 110xxxxx 10xxxxxx. The underlined 11 “x” positions in the bit pattern store the 11-bit code point. The code point is justified to the right, and 0 is stored in any leftover “x” positions. This 2-byte value is the encoded result. For instance, when the code point AE(16) for Registered Sign character “®” is represented in binary, it is 10101110. When this is stored right-justified in the “x” positions in the bit pattern above, it is 110xxx10 10101110. When 0 is stored in the three leftover “x” positions, the UTF-8 encoding for Registered Sign character “®” 11000010 10101110 is obtained. In decimal form, this corresponds to {194, 174}.

The function encode converts a Unicode code point that is passed as an argument to UTF-8 encoding, and returns an integer array that stores it one byte per element from the start of the array. It is assumed that only an integer value that ranges from 80(16) to 7FF(16) is passed to encode as an argument.

[Program]
○ integer []: encode(integer: codePoint)
/* the initial value of utf8Bytes is the value when “x”s in the bit pattern are replaced
with 0, divided into two 8-bit blocks, and each deemed to be binary */
integer []: utf8Bytes ← {192, 128}
utf8Bytes[2] ← utf8Bytes[2] + (codePoint mod blank)
utf8Bytes[1] ← utf8Bytes[1] + integer part of (codePoint ÷ blank)
return utf8Bytes

Answer group

Explanation

64 — the second byte carries the low 6 bits of the code point, so both blanks split the value at 26.

In 110xxxxx 10xxxxxx the six rightmost x positions belong to the second byte and the five left ones to the first. Dividing by 26 = 64 separates them:

  • •second byte: codePoint mod 64 is the low 6 bits, added to the base 128 (10000000)
  • •first byte: the integer part of codePoint ÷ 64 is the remaining upper bits, added to the base 192 (11000000)

Check with the Registered Sign, code point AE (hexadecimal) = 174: 174 mod 64 = 46 and 128 + 46 = 174; 174 ÷ 64 = 2 remainder 46, and 192 + 2 = 194. The result {194, 174} matches the example.

Answer (c)

Why not others:

  • •(a) 2 — moves only one bit into the second byte: 174 gives {279, 128}, and 279 does not even fit in a byte
  • •(b) 32 — 25 is the payload width of the first byte, not the second; 174 gives {197, 142}
  • •(d) 256 — assumes the whole low byte fits into the second byte, but it holds only 6 bits; 174 gives {192, 302}
  • •(e) utf8Bytes[1] — divides by 192, a byte base rather than a bit boundary: 174 gives {192, 302}
  • •(f) utf8Bytes[2] — first 128, then the already updated 174, so the divisor changes between the two lines: 174 gives {193, 174}

Key rule: Splitting a number into bit fields is mod 2k for the low k bits and integer division by 2k for the rest, where k is the width of the lower field.

Math & Numbers · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.