← All lessons

The Hexadecimal Number System

IGComputer Science
~22 min
Cambridge IGCSE 0478 — Topic 1.1 Number Systems

By the end of this lesson you will be able to

  1. Given any 2-digit hexadecimal number (00–FF), convert it to its denary equivalent within 30 seconds.
  2. Given any denary number from 0 to 255, convert it to a 2-digit hexadecimal number with full working.
  3. Convert between 8-bit binary numbers and 2-digit hexadecimal numbers using the 4-bit grouping method.
  4. Identify which symbols are valid in hexadecimal and explain why hex is preferred over binary or denary for human-readable representations of byte-level data.
Prerequisites (3)
  • Lesson 1 — The Binary Number System (conversions both directions, place value)
  • Know that 8 bits = 1 byte, range 0 to 255
  • Comfortable with multiplication and division of small whole numbers

2. Hook

You've opened Photoshop, or typed a colour into CSS, or picked a highlight in a text editor's theme. You've seen codes that look like this:

#FF5733 · #1A1A2E · #00BFFF

Six characters. Two letters, four digits — sometimes more letters, sometimes none. No one ever explains what they mean. You copy them, paste them, and move on.

Here's the question: why are colours written like this? Why not as the three numbers a computer actually uses? Why not as the raw bits a computer actually stores? What is the point of this in-between form that no other counting system in your life uses?

By the end of this lesson you'll decode #FF5733 on sight — and understand why every serious computing context (web development, networking, debugging, assembly code) picks hex over the alternatives.

3. Why this matters

Hex shows up wherever bytes need to be read by humans. A short list, all drawn from real engineering:

Real-world anchor. The dark navy colour behind the lesson panels on this site is #1A1A2E. By the end of this lesson you'll know, without looking anything up, that that means 26 red, 26 green, 46 blue — and you'll see it in the binary exactly the way your GPU does.

4. Prerequisites refresher

This lesson builds directly on Lesson 1 — The Binary Number System. You need to be comfortable with:

If those feel shaky, spend five minutes on Lesson 1 before continuing — the hex method here collapses if the binary underneath is not solid.

30-second recap — a 4-bit group (called a nibble) has place values 8,4,2,18, 4, 2, 1. It can represent any denary value from 0 to 15. Remember this — it is the whole trick of this lesson.

5. Intuition pass

Three ways to write the same number

Consider the number 243. There are three ways a computer can describe it:

FormWritten asLength
Denary (base 10)2433 characters
Binary (base 2)111100118 characters
Hex (base 16)F32 characters

All three are the same quantity. They describe the same pattern of bits in memory. They're written differently because different audiences need different things out of them.

The sixteen hex digits

Base 16 means you need 16 different symbols. You already have 0–9. The standard hex convention extends with the first six letters of the alphabet:

Denary0123456789101112131415
Hex0123456789ABCDEF
Binary (4 bits)0000000100100011010001010110011110001001101010111100110111101111

Worth memorising. The leap from 9 to A is the part that trips people up — remember that after 9 we need six more symbols, so we reuse A through F. F = 15 is the biggest single hex digit, the same way 9 is the biggest single denary digit.

Try it on real colours

The tool below is the best way to make hex click. Every web colour is three bytes glued together — one for red, one for green, one for blue. Each byte is written as two hex digits. Drag the sliders, or click a preset.

hexFFdec255bin11111111
hex57dec87bin01010111
hex33dec51bin00110011
Try:
Drag the sliders. Hex is the same number as denary, written in base 16.

Try these, in order:

  1. Click Red. What are the three hex pairs? What does that tell you?
  2. Click White. Now all three are FF. Why does that make sense? (Hint: what is FF in denary?)
  3. Drag the R slider to 128. What happens to the hex? Why is it 80, not a rounder-looking number?
Checkpoint — predict first

Before you touch the sliders again: the colour code #808080 is a medium grey. Predict what R, G, B are in denary — without converting — and then check.

Write something first.

6. Formal pass

Definitions

Positional notation

An nn-digit hex number hn1hn2h1h0h_{n-1} h_{n-2} \ldots h_1 h_0 has the denary value:

i=0n1hi16i\sum_{i=0}^{n-1} h_i \cdot 16^i

where each hih_i is a value from 0 to 15. The place values, from right to left, are 1,16,256,4096,1, 16, 256, 4096, \ldots — powers of 16.

For a 2-digit hex number, the place values are:

Hex positionLeft digitRight digit
Place value161

So the hex number A7 equals A×16+7×1=10×16+7=167A \times 16 + 7 \times 1 = 10 \times 16 + 7 = 167 in denary.

Range

With nn hex digits, you have 16n16^n patterns, representing values 0 to 16n116^n - 1.

That correspondence — nn hex digits = 4n4n bits — is the reason hex exists.

Checkpoint — quick check

How many denary values can a 3-digit hex number represent?

Choose one option
Pick an option first.

Why hex, specifically?

You could imagine a base-8 (octal) system, or base-4, or base-32. Why did base-16 win?

Two reasons. First: bytes are 8 bits, and 8 splits neatly into two groups of 4 — so two hex digits is exactly one byte. No wasted space, no awkward overflow. Second: four bits fits one "familiar-sized" digit — you can glance at a byte and read off its two halves instantly once you know the 16 symbols. Octal (base 8) would take three digits per byte and feel cramped; base-32 would need too many unfamiliar symbols.

Hex hit the sweet spot for the hardware word sizes that won out in the 1970s, and everything since has followed.

7. Application pass

The 4-bit grouping method

The reason hex is easy to work with is that you never need to convert through denary. Binary and hex translate directly, nibble by nibble.

That's the whole method. Watch it happen live — click any bit below and see the hex update:

8 bits split into two nibbles
10110101
= hex
B5
= 181 denary
8
4
2
1
11 in denary
B
hex
8
4
2
1
5 in denary
5
hex
Click a bit, or Tab and press Space. Each group of 4 bits maps to exactly one hex digit — that is the whole trick.

Try making these binaries and reading off the hex:

  1. 11111111 → what hex? (Should be a familiar value.)
  2. 00001111 → what hex? Why does the left nibble being all 0s give a leading 0 in hex?
  3. 10101010 → what hex? Toggle a single bit and see how much the hex changes.
Checkpoint — concept check

You want to convert hex 4B to binary. What do you do?

Choose one option
Pick an option first.

Worked example: hex → denary

Convert A7 to denary using positional notation.

A716=A×16+7×1=10×16+7=160+7=16710A7_{16} = A \times 16 + 7 \times 1 = 10 \times 16 + 7 = 160 + 7 = 167_{10}

The only trick is remembering that A = 10. Everything else is arithmetic.

Worked example: denary → hex

Convert 200 to hex.

  1. How many 16s fit into 200? 16×12=19216 \times 12 = 192 fits, but 16×13=20816 \times 13 = 208 is too big. So the left (16s) digit is 12.
  2. 12 in hex is C.
  3. Remainder: 200192=8200 - 192 = 8. So the right (1s) digit is 8.
  4. Answer: C8. Verify: C×16+8=192+8=200C \times 16 + 8 = 192 + 8 = 200. ✓

A third method exists — go via binary. Convert 200 to 8-bit binary (11001000), split into nibbles (1100 1000), convert each to hex (C and 8). Same answer, C8. Use whichever feels faster; both are correct.

Back to the anchor

The dark navy panel colour from Section 3 was #1A1A2E. Now you can decode it without tools:

So #1A1A2E is rgb(26, 26, 46) — low on everything, slightly more blue than the other two, which is why it reads as a cool dark navy rather than neutral grey.

8. Summary

Six things worth remembering in six months:

  1. Hex is base 16. Digits are 0–9 and A–F, where A=10, B=11, C=12, D=13, E=14, F=15.
  2. 2 hex digits = 1 byte = 8 bits. This is the single reason hex exists.
  3. Binary ↔ hex is direct. Each 4-bit nibble maps to exactly one hex digit. Never route through denary unless it helps you.
  4. Hex → denary: multiply each digit by its place value (16s, 1s) and add.
  5. Denary → hex: find how many 16s fit in, convert to a hex digit; the remainder is the second digit.
  6. Hex shows up wherever humans read bytes: web colours, MAC addresses, memory addresses, error codes.

9. Quiz

Seven questions, mixed types. Expect about 10 minutes.

Question 1 of 7
0 / 21
Multiple choice2 points

What denary value does the hexadecimal digit F represent?

Answer options

Practice exam available

Take the 15-question exam for this lesson

Auto-graded multiple-choice questions. You'll see your percentage, letter grade, and a question-by-question review after submitting.

Start exam →

10. Further practice

Work through these problems — solutions in practice-solutions.md.

  1. Convert 3F to denary.

  2. Convert BE to denary.

  3. Convert 100 (denary) to hex.

  4. Convert 254 (denary) to hex.

  5. Convert binary 11100110 to hex.

  6. Convert hex D2 to binary.

  7. The hex colour #1E90FF ('Dodger Blue') has three channel values. Convert each pair to denary and state which channel dominates.

  8. Explain in two sentences why one hex digit corresponds to exactly one nibble (4 bits), and why this makes hex–binary conversion faster than denary–binary conversion.

Extension (A* territory): A MAC address is 48 bits long. How many hex digits does that take? How many possible MAC addresses exist? (Your phone's MAC is one of them.)

11. Further reading

Pedagogy and framings adopted here:

Syllabus and exam resources:


Version 1 — published 2026-04-24.