Worked example · Computer Science · Year 9

Converting hexadecimal colour codes

LNF: Numeracy → Understanding the number system helps us to represent and compare relationships between numbers and quantities → Relationships within the number system

What this is

A complete, secure Year 9 answer, annotated so you can see which success criterion each part meets. It is also the answer key. Headline answers: sea-grass green is 30, 90, 60; sand gold is 242, 193, 78; lifeboat red is 215, 38, 61; Sunset is #C82D63 and Moonlight is #8080FF. The most common mistakes are forgetting that A to F stand for 10 to 15, and writing a binary answer with fewer than 8 bits.

Step 1: warm-up

QuestionAnswer
8 binary column values, left to right128, 64, 32, 16, 8, 4, 2, 1
160, 161, 1621, 16, 256
A, C and F in denary10, 12, 15
Largest 8-bit number11111111 = 255 = FF

Every column value is a power of the base. Evidences criterion 1.

Step 2: website colours to the lighting desk

ColourPairWorkingDenaryBinary
Sea-grass green #1E5A3C1E(1 × 16) + 14 = 16 + 14300001 1110
5A(5 × 16) + 10 = 80 + 10900101 1010
3C(3 × 16) + 12 = 48 + 12600011 1100
Sand gold #F2C14EF2(15 × 16) + 2 = 240 + 22421111 0010
C1(12 × 16) + 1 = 192 + 11931100 0001
4E(4 × 16) + 14 = 64 + 14780100 1110
Lifeboat red #D7263DD7(13 × 16) + 7 = 208 + 72151101 0111
26(2 × 16) + 6 = 32 + 6380010 0110
3D(3 × 16) + 13 = 48 + 13610011 1101

(b) Sand gold has the most red (242). You can tell from the first digit of the first pair: F is the biggest hex digit, and the left digit is worth 16 times as much as the right one. Lifeboat red starts with D (215), sea-grass green with 1 (30).

Every binary answer is 8 bits, written as two nibbles that match the two hex digits. Check for 3C: 0011 1100 = 32 + 16 + 8 + 4 = 60. Evidences criteria 2 and 6.

Step 3: lighting scenes to the website

SceneDenaryWorkingHex
Sunset200200 ÷ 16 = 12 remainder 8; 12 is CC8
4545 ÷ 16 = 2 remainder 13; 13 is D2D
9999 ÷ 16 = 6 remainder 363
Moonlight128128 ÷ 16 = 8 remainder 080
128as above80
255255 ÷ 16 = 15 remainder 15; 15 is FFF

(b) Sunset #C82D63. Moonlight #8080FF.

(c) C8 = (12 × 16) + 8 = 192 + 8 = 200. Correct.

Remainders of 10 or more are changed to letters. The check converts back the other way. Evidences criteria 3 and 6.

Step 4: binary to hex

BinaryTwo nibbles and hexDenary
101101101011 = 11 = B; 0110 = 6; so B6(11 × 16) + 6 = 182
011111000111 = 7; 1100 = 12 = C; so 7C(7 × 16) + 12 = 124

Check in binary: 10110110 = 128 + 32 + 16 + 4 + 2 = 182. 01111100 = 64 + 32 + 16 + 8 + 4 = 124. Both match. Evidences criteria 4 and 6.

Step 5: brighter and dimmer with shifts

(a) 22 = 16 + 4 + 2 = 00010110.

(b) Left 1 place: 00101100 = 32 + 8 + 4 = 44. Left 2 places: 01011000 = 64 + 16 + 8 = 88. One left shift multiplies by 2; two left shifts multiply by 4 (2 × 2).

(c) 150 = 128 + 16 + 4 + 2 = 10010110. Shifted left: 1 00101100. Only 8 bits fit, so the leading 1 falls off and the desk keeps 00101100 = 44. The true answer, 300, is bigger than 255, the largest number 8 bits can hold. This is overflow: the bit worth 256 is lost, and 300 − 256 = 44.

The explanation links overflow to the 8-bit limit and shows exactly which value was lost. Evidences criterion 5.

Step 6: why hex?

(a) 256 × 256 = 65,536. 65,536 × 256 = 16,777,216 colours. This is also 224, because a colour code uses 24 bits.

(b) Hex is much shorter: 6 characters instead of 24 bits, so it is quicker to type and read. It is less likely to be copied wrongly, and because 1 hex digit is exactly 4 bits it is still easy to change into binary.

The answer links hex to binary through the nibble, not just “it is easier”.

If you finish early: answers

Why this response is secure