A1.2.1 · Data representation and computer logic
Binary and hexadecimal
By the end you can
Convert between denary, binary and hexadecimal, and use bits, bytes and prefixes (kB vs KiB) correctly.
Inside a computer, every piece of data is held by millions of tiny electronic switches, each either off or on. Two states are easy to make, cheap, and hard to confuse even when the signal is noisy, so computers count with two symbols: 0 and 1. That is . Everything in this chapter, from numbers to emoji to music, comes down to patterns of these two symbols.
A single 0 or 1 is a . Four bits are a , and eight bits are a , the unit memory is usually measured in.
Place value, in base 2#
In ordinary (base 10) numbers, each place is worth ten times the one to its right: units, tens, hundreds. Binary works the same way with twos. For one byte the places are worth 128, 64, 32, 16, 8, 4, 2 and 1. A number is the total of the places that hold a 1, so 10110101 is 128 + 32 + 16 + 4 + 1 = 181.
Range: 0 to 255
Binary → denary
Add up the place values of every 1.
Working
- 128 + 32 + 16 + 4 + 1 = 181
Denary → binary
Keep dividing by 2. Read the remainders from the bottom up.
Working
- 181 ÷ 2 = 90 r 1
- 90 ÷ 2 = 45 r 0
- 45 ÷ 2 = 22 r 1
- 22 ÷ 2 = 11 r 0
- 11 ÷ 2 = 5 r 1
- 5 ÷ 2 = 2 r 1
- 2 ÷ 2 = 1 r 0
- 1 ÷ 2 = 0 r 1
- Bottom up: 10110101
Binary → hexadecimal
Split into groups of 4 bits from the right. Each group is one hex digit.
Working
- 1011 = 11 = B
- 0101 = 5 = 5
- So B5
Or by dividing by 16
- 181 ÷ 16 = 11 r 5 (5)
- 11 ÷ 16 = 0 r 11 (B)
Denary to binary, by hand
Two methods, both accepted in exams. Take 181:
Subtract place values
Work from the biggest place value down. 128 fits into 181 (put a 1; 53 left). 64 does not (0). 32 fits (1; 21 left). 16 fits (1; 5 left). 8 does not (0). 4 fits (1; 1 left). 2 does not (0). 1 fits (1). So 10110101.Or divide by 2
Divide by 2 repeatedly, writing down each remainder: 181 → 90 r1 → 45 r0 → 22 r1 → 11 r0 → 5 r1 → 2 r1 → 1 r0 → 0 r1. Read the remainders from the last one up: 10110101.
Hexadecimal: binary for humans#
Long rows of bits are hard to read and easy to copy wrongly. (base 16) fixes this. It needs sixteen digits, so after 0–9 it uses the letters A to F for 10 to 15. Because 16 = 2⁴, one hex digit stands for exactly four bits: one nibble. A byte is always exactly two hex digits.
0
0000
= 0
1
0001
= 1
2
0010
= 2
3
0011
= 3
4
0100
= 4
5
0101
= 5
6
0110
= 6
7
0111
= 7
8
1000
= 8
9
1001
= 9
A
1010
= 10
B
1011
= 11
C
1100
= 12
D
1101
= 13
E
1110
= 14
F
1111
= 15
Binary → hex
Split the bits into groups of four from the right (pad with 0s on the left if needed), then swap each group for its hex digit: 1011 0101 → B 5 → B5.Hex → binary
Swap each hex digit for its four bits: 3E → 0011 1110.Hex ↔ denary
Places in hex are worth 1, 16, 256 ... so B5 = 11 × 16 + 5 = 181. The other way, divide by 16: 181 ÷ 16 = 11 r 5 → B5.
You see hex wherever people need to read raw bytes: web colour codes, memory addresses in error messages, MAC addresses on network cards, and the bytes of a file in a hex editor. Colours are a good example to play with.
Each channel is one byte (8 bits, 0–255), so a colour is 24 bits and there are 224 = 16,777,216 of them. Each nibble (4 bits) is exactly one hex digit, which is why six hex digits describe any colour.
How many values fit in n bits?#
Each extra bit doubles the number of possible patterns. One bit has 2 (0, 1); two bits have 4 (00, 01, 10, 11); n bits have 2ⁿ. As unsigned whole numbers they run from 0 to 2ⁿ − 1, so a byte holds 0 to 255 and 16 bits hold 0 to 65,535. The same rule tells you how many colours a pixel can have, or how many characters a character set can hold, which you will meet in A1.2.2.
Units: kilo means 1000, unless it means 1024#
Larger amounts of data use prefixes. There are two families, and mixing them up is one of the most common errors in calculation questions (see ):
- Decimal prefixes go up in 1000s, like the rest of science: 1 kB = 1000 bytes, 1 MB = 1000 kB, 1 GB = 1000 MB.
- Binary prefixes go up in 1024s (2¹⁰), which suits memory sizes: 1 KiB = 1024 bytes, 1 MiB = 1024 KiB, 1 GiB = 1024 MiB.
On the box (decimal, × 1000)
1 TB
1,000,000,000,000 bytes ÷ 10004
What the computer shows (binary, × 1024)
931.3 GiB
1,000,000,000,000 bytes ÷ 10243
Same number of bytes, different unit. Each step up is 1024 instead of 1000, so the binary figure shrinks by about 9.1% at the tera level. Nothing is missing: the drive just uses decimal prefixes and the operating system uses binary ones (often labelled GB anyway, which is where the confusion comes from).
| Decimal (SI) | Bytes | Binary (IEC) | Bytes |
|---|---|---|---|
| 1 kB | 10001 = 1,000 | 1 KiB | 10241 = 1,024 |
| 1 MB | 10002 = 1,000,000 | 1 MiB | 10242 = 1,048,576 |
| 1 GB | 10003 = 1,000,000,000 | 1 GiB | 10243 = 1,073,741,824 |
| 1 TB | 10004 = 1,000,000,000,000 | 1 TiB | 10244 = 1,099,511,627,776 |
Check yourself
Binary, hex and units
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
6 questions · 14 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Calculate the denary value of the binary number 10110110. Show your working.
[2]Calculate: Work out the number, showing the working.
2.Calculate the hexadecimal representation of the denary number 203. Show your working.
[2]Calculate: Work out the number, showing the working.
3.Explain why programmers often write values in hexadecimal rather than binary.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
4.State how many different values can be represented with 12 bits.
[1]State: Give a short answer, no explanation needed.
5.A file is 3 MiB. Calculate its size in bytes.
[2]Calculate: Work out the number, showing the working.
6.Justify why computers store data in binary rather than in denary.
[4]Justify: Give the reasons or evidence that support the answer or decision.
Past papers
Old exam questions on this topic
From HL Paper 1, May 2014 to November 2025. These papers were set on the previous syllabus, so the wording may differ from today's exam, but the topic is the same. Find the questions and markschemes in your school's past-paper pack.
| Paper | Question | Marks | About |
|---|---|---|---|
| November 2025 | 4 | 2 | Hex to binary and back |
| May 2024 TZ1 | 7 | 2 | Denary to binary, binary to hex |
| May 2022 | 7 | 4 | Denary to binary and to hex |
| May 2021 | 5 | 2 | Hex to denary |
| November 2021 | 2 | 1 | Binary to hex |
| May 2019 | 6 | 1 | Binary to hex |
| November 2019 | 3(a) | 1 | Why hex is used |
| May 2016 | 5 | 2 | Hex to 8-bit binary |
| November 2014 | 3 | 2 | How binary and hex relate |
In a nutshell
- Computers store everything as bits: 0s and 1s. 4 bits make a nibble, 8 bits a byte.
- In binary each place is worth twice the one to its right: 128, 64, 32, 16, 8, 4, 2, 1 for a byte.
- Binary → denary: add the place values of the 1s. Denary → binary: subtract the largest place values that fit, or keep dividing by 2 and read the remainders upwards.
- Hexadecimal (base 16) uses 0–9 and A–F. One hex digit = one nibble, so binary ↔ hex is done in groups of four bits.
- n bits give 2ⁿ different values: 0 to 2ⁿ − 1 as unsigned numbers.
- kB, MB, GB go up in 1000s; KiB, MiB, GiB go up in 1024s. Read the unit carefully in calculations.
