02 — Practice solutions
These are independently written explanations, not an official marking scheme.
02A
1×256 + 12×16 + 2 = 450. Twelve bits: 0001 1100 0010. Hex is more compact and easier to transcribe, with a direct four-bit mapping per digit.
Reasoning
Three hexadecimal digits correspond to twelve binary bits, so translate each into one nibble. The leading hex1 becomes0001; dropping its zeroes would violate the requested12-bit width. For denary, the place weights are256,16,1.
02B
77 = 64+8+4+1 → 01001101. U+1F631 = 1×65536 + 15×4096 + 6×256 + 3×16 + 1 = 128561. Unicode supports many writing systems and symbols such as emoji that ASCII cannot represent. Its byte representation depends on the encoding; UTF-8 is variable-length, so the universal two-byte claim is false.
Reasoning
M asks for a fixed-width ASCII bit pattern, whereas U+1F631 asks for the numeric value of a hexadecimal code point. Do not output UTF-8 byte sequences for the second task. The final explanation asks about both repertoire and encoding size.
02C
def hex_to_binary(text):
digits = "0123456789ABCDEF"
groups = ["0000", "0001", "0010", "0011",
"0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111"]
result = ""
for digit in text:
result += groups[digits.index(digit)]
return result"0A" → "00001010"; "F0" → "11110000". Leading zeroes preserve the specified four-bit group for each digit. The contract supplies valid uppercase hexadecimal input.