← Data representation

Hex: binary in fours

Hexadecimal (hex) has sixteen digits, 0 to 9 then A to F (10 to 15). One hex digit is exactly four bits, so a byte is always two hex digits: 1010 0011 is A3. It's a short way to write binary, used for web colours, memory addresses and error codes. Like binary, it's a public rule, not a secret.

Web colours look like #FF8800 and error codes like 0x1F. Why do programmers write numbers with letters in them?

Binary needs a lot of digits: 255 is 11111111. Programmers write it shorter, in a way that still shows the bits.

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

What is FF?

In the web colour #FF8800, each pair of characters is one number from 0 to 255. What number is FF?

TryTry it on the board and compare the result with your prediction.

Try: every card up

Was your prediction right? Now flip the left-hand group down. What's left?

Try it yourselfYour edits are saved in this browser.

Turn every card face up. What does the hex under each group of four say?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: four bits, one digit

Worked exampleBefore each step, say what you think comes next.
  1. 0–9, A–F0\text{–}9,\ A\text{–}FSixteen digits: A is 10, B 11, C 12, D 13, E 14, F 15.

Now read hex B.

Hex digits go 0 to 9, then A, B, C, D, E, F for 10 to 15. What number is hex B?

Sam reads a hex number. Click the line where it first goes wrong.

Write the byte 0011 1100 in hex.

ModifyChange the problem on purpose and see what happens.

Vary: make the hex

Try it yourselfYour edits are saved in this browser.

Make the hex read 0F.

Use the board. This ticks when you get there.

Now make it read 80.

Use the board. This ticks when you get there.

Make it read A3.

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Hex in the wild

In #FF8800, red is FF, green is 88 and blue is 00. What number is the green, 88?

A message in a file reads 6869. It's hex. Is it hidden from someone who copies the file?

Review: what number is the binary 1011?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

The badge colour

Then: write your favourite colour as three numbers from 0 to 255, then as hex.

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

How many whole sixteens fit in 200? That's the left digit.

Another hint

Twelve sixteens is 192. What's left over is the right digit.

Another hint

12 is C. Set the left group to 1100 and the right group to the leftover.

The club badge's red value is 200. Set the cards so they hold 200, and read its hex. (The number is hidden: use the hex.)

Use the board. This ticks when you get there.

Now you can
Next lesson7. Why binary: logic gatesA switch has two states that are easy to tell apart: off (0) and on (1). Wire two switches in a line and the lamp lights only when both are on: an AND gate. Side by side, either one will do: an OR gate. Gates like these, made of tiny electronic switches, combine bits to do every calculation, which is why computers are built on binary.
For teachers

Students group binary cards in fours to read and write hex, see that one hex digit is exactly four bits and a byte is two hex digits, read web colours, and meet hex as a public rule (AC9TDI8K04 node 1, binary representation of integers, written short). Optional; Encoding is not encryption (Capture the flag) decodes hex and is the natural place to point students who skipped it. About 35 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Do the boards yourself first. Students need Bits and binary numbers and How many patterns? (four bits make 16 patterns).

The one idea: four bits make exactly 16 patterns, so one hex digit stands for four bits, and two hex digits for a byte. Hex is binary written short, not a new kind of number.

Added 25 Oct 2026 to answer the roadmap's open question (hex in the colour lesson, or Years 9–10?): an optional lesson after How many patterns, with one line in Colour and images. It is optional because the descriptor doesn't name hex. Encoding is not encryption (Capture the flag) uses hex but doesn't list it in assumes:, since an optional lesson can't satisfy that check.

Running the lesson

  1. Predict: students who chose 1515 read each F as 15 and joined them; ask how many cards each F stands for.
  2. Try: ask how many hex digits a byte needs, and why never three.
  3. Worked example: ask what the left digit counts.
  4. Make: let students work out 200 on paper first, then check with the cards.

The hard part (on purpose)

Joining the two digits like decimal (1F as 115). Every time, ask what the left digit counts: sixteens.

When students get stuck

Stretch and support

Stretch: Memory addresses are often written in hex, like 0x7FFF. How many bits does each hex digit stand for, so how many bits is that address?

Support: A card: 0–9 as usual, A 10, B 11, C 12, D 13, E 14, F 15. One hex digit = four bits; two = a byte.

Where it leads

Next: Why binary: logic gates.

Links: Colour and images (RGB values), Capture the flag › Encoding is not encryption (hex as a public rule).

What each step is for