Syllabus & Goals 3 min
Cambridge 1.1 · Number systems Paper 1 · Computer Systems
By the end of this lesson you can:
- Convert a denary number to binary by subtraction and by division by 2.
- Convert between hexadecimal and binary (in nibbles) and between hexadecimal and denary (both ways).
- Explain why hexadecimal is used — error codes, MAC addresses, IP addresses and HTML colour codes.
Textbook: Chapter 1, §1.1.2–1.1.3 (pp. 4–14)
Recap / Warm-Up 5 min
Last lesson you converted binary to denary by adding place values. Now go the other way, and meet a third number system.
Quick starter
Using the headings 128 64 32 16 8 4 2 1, which columns add up to 20?
Reveal the answer
16 + 4 = 20, so 20 in binary is 00010100. That idea is the first conversion method below.
Key Concept — converting & hexadecimal 14 min
1 · Denary → binary: two methods
Method 1 — successive subtraction. Subtract the largest power of 2 that fits. Repeat with what is left until you reach 0. Put a 1 in every column you used and 0 in the rest.
Method 2 — successive division by 2. Divide by 2 and write down the remainder (0 or 1), even when it is 0. Keep dividing the result until it reaches 0. Read the remainders from the bottom up.
2 · The hexadecimal (base 16) system
Hexadecimal (hex) is base 16, so it needs 16 digits: 0–9 then A B C D E F for 10 to 15. Its headings are powers of 16: 1, 16, 256, 4096, 65 536.
| Binary | Hex | Denary | Binary | Hex | Denary |
|---|---|---|---|---|---|
| 0000 | 0 | 0 | 1000 | 8 | 8 |
| 0001 | 1 | 1 | 1001 | 9 | 9 |
| 0010 | 2 | 2 | 1010 | A | 10 |
| 0011 | 3 | 3 | 1011 | B | 11 |
| 0100 | 4 | 4 | 1100 | C | 12 |
| 0101 | 5 | 5 | 1101 | D | 13 |
| 0110 | 6 | 6 | 1110 | E | 14 |
| 0111 | 7 | 7 | 1111 | F | 15 |
3 · Binary ↔ hex: group in fours
Binary → hex: start at the right and split the bits into groups of 4. If the last group is short, fill it with 0s on the left. Replace each group with its hex digit.
Hex → binary: replace each hex digit with its 4-bit pattern, then join the groups.
1011011101 from the right. The left group has only two bits, so two 0s are added in front. The answer is 2DD.Diagram · Advaslearning Hub4 · Hex ↔ denary
Hex → denary: change any letters to numbers first (A = 10 … F = 15). Multiply each digit by its heading (256, 16, 1) and add the results.
Denary → hex: divide by 16 repeatedly, writing the remainder (0–15) each time. Turn remainders 10–15 into A–F, then read them from the bottom up.
5 · Why use hex? Four real uses
Computers only work in binary. But long binary numbers are hard for people to read, copy and remember. One hex digit replaces four bits, so 1011111000101001 becomes just BE29. Fewer digits means fewer mistakes.
Error codes
Error messages are often shown in hex. The values refer to the memory location of the error. A programmer reads them to find the fault.
MAC addresses
A number that uniquely identifies a device's network interface card (NIC). 48 bits, shown as six pairs of hex digits.
IP addresses
IPv4 is 32 bits, usually written in denary (192.168.1.10 = C0.A8.01.0A in hex). IPv6 is 128 bits, written as eight groups of four hex digits separated by colons.
HTML colour codes
#RRGGBB — two hex digits each for the intensity of red, green and blue on a web page.

00:11:14) are identical — that is the manufacturer's code. Only the last three pairs, the device serial number, change.Photo: Solomon203, CC BY-SA 4.0, via Wikimedia Commonsa3 = A3).Diagram · Advaslearning Hub#FF9966 means red = FF (255), green = 99 (153), blue = 66 (102). Each part has 256 possible values, so there are 256 × 256 × 256 = 16 777 216 colours.Diagram · Advaslearning Hub#FF0000 gives pure red, #00FF00 pure green and #FF8000 orange (full red, half green, no blue).Worked Example 12 min
Worked example 1 · denary 213 → 8-bit binary (both methods)
Method 1 — subtraction
- 128 fits into 213: 213 − 128 = 85. Put 1 under 128.
- 64 fits into 85: 85 − 64 = 21. Put 1 under 64.
- 32 does not fit into 21 → 0. 16 fits: 21 − 16 = 5. Put 1 under 16.a column that does not fit still needs its 0 written in.
- 8 does not fit → 0. 4 fits: 5 − 4 = 1. 2 does not fit → 0. 1 fits: 1 − 1 = 0. Stop.
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bit | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| Adds | 128 | 64 | – | 16 | – | 4 | – | 1 |
Method 2 — division by 2 (the same answer, as a check):
| Step | Division | Result | Remainder |
|---|---|---|---|
| 1 | 213 ÷ 2 | 106 | 1 |
| 2 | 106 ÷ 2 | 53 | 0 |
| 3 | 53 ÷ 2 | 26 | 1 |
| 4 | 26 ÷ 2 | 13 | 0 |
| 5 | 13 ÷ 2 | 6 | 1 |
| 6 | 6 ÷ 2 | 3 | 0 |
| 7 | 3 ÷ 2 | 1 | 1 |
| 8 | 1 ÷ 2 | 0 | 1 |
| Read the remainders from the bottom up: 11010101 | |||
Answer: 11010101. Two methods agreeing is a quick way to check your work in the exam.
Worked example 2 · binary 1011011101 → hex
- Split from the right into fours: 10 1101 1101.
- Pad the short left group with 0s: 0010 1101 1101.each hex digit needs exactly four bits; leading 0s do not change the value.
- Convert each nibble: 0010 = 2 = 2 1101 = 13 = D 1101 = 13 = D
- Answer: 2DD.
Worked example 3 · hex A2F → binary
- A = 10 = 1010; 2 = 0010; F = 15 = 1111.keep the leading 0s inside each group, or the digits shift columns.
- Join them:
101000101111.
Worked example 4 · hex 3B7 → denary
| Heading | 256 | 16 | 1 |
|---|---|---|---|
| Hex digit | 3 | B (= 11) | 7 |
| Digit × heading | 3 × 256 = 768 | 11 × 16 = 176 | 7 × 1 = 7 |
- Change B to 11 first. a letter cannot be multiplied until it is a number.
- Add the products: 768 + 176 + 7 = 951.
- Answer: 951. Marks: correct method (1); correct answer (1).
Worked example 5 · denary 1500 → hex
| Step | Division | Result | Remainder | Hex digit |
|---|---|---|---|---|
| 1 | 1 500 ÷ 16 | 93 | 12 | C |
| 2 | 93 ÷ 16 | 5 | 13 | D |
| 3 | 5 ÷ 16 | 0 | 5 | 5 |
| Read the remainders from the bottom up: 5DC | ||||
- 1500 ÷ 16 = 93 remainder 12 → C.
- 93 ÷ 16 = 5 remainder 13 → D.
- 5 ÷ 16 = 0 remainder 5 → 5. The result is 0, so stop.
- Read upwards: 5DC. Check: 5 × 256 + 13 × 16 + 12 = 1280 + 208 + 12 = 1500 ✓.converting back is the fastest way to catch a slip.
The division method as an algorithm
// Denary to 8-bit binary by division by 2 DECLARE Number, Index : INTEGER DECLARE Bits : ARRAY[1:8] OF INTEGER Number ← 213 FOR Index ← 8 TO 1 STEP -1 Bits[Index] ← Number MOD 2 Number ← Number DIV 2 NEXT Index FOR Index ← 1 TO 8 OUTPUT Bits[Index] NEXT Index
# Denary to binary by division by 2 number = 213 bits = "" while number > 0: bits = str(number % 2) + bits number = number // 2 print("Binary is", bits)
Binary is 11010101
Try It Yourself 12 min
Goal: convert denary 77 to 8-bit binary by both methods, and check they agree.
Goal: convert 10111110 and 1111000101 to hex, then convert hex 7E to binary and to denary.
Goal: convert denary 2748 to hex using division by 16, then to binary. Check your answer by converting the hex back to denary.
Hint
You should get three remainders, all of them 10 or more — so all three hex digits are letters.
📝 Exam Practice 10 min
(a) Convert the binary number 11001010 to hexadecimal. (b) Convert the hexadecimal number 9C to denary.
Mark scheme
- (a)
1100 1010→CA(1). - (b) 9 × 16 + 12 = 144 + 12 =
156(1).
Explain why programmers often use hexadecimal instead of binary.
Mark scheme
- One hex digit represents four binary digits, so hex numbers are shorter (1).
- Shorter numbers are easier for humans to read / remember / copy, with fewer errors (1).
A router has the MAC address 00-40-96-5E-2C-1A. Describe the MAC address and its format.
Mark scheme
- It uniquely identifies a device (its network interface card) on a network (1).
- It is 48 bits, written as six pairs of hexadecimal digits (1).
- The first three pairs (
00-40-96) are the manufacturer's code (1). - The last three pairs (
5E-2C-1A) are the device's serial number (1). Max 3.
A web designer picks a colour with red = 201, green = 122 and blue = 53 (denary). Calculate the HTML colour code. Show your working.
Mark scheme
- Red: 201 ÷ 16 = 12 r 9 →
C9(1). - Green: 122 ÷ 16 = 7 r 10 →
7A(1). - Blue: 53 ÷ 16 = 3 r 5 →
35; so#C97A35(1).
Recap & Key Terms 3 min
Convert denary to binary by subtraction or by dividing by 2 (read remainders upwards). Hex is base 16 (0–9, A–F). Four bits make one hex digit, so binary ↔ hex is grouping in fours. Hex ↔ denary uses the headings 256, 16, 1 or division by 16. People use hex because it is shorter than binary.
- Hexadecimal number system
- A number system based on 16 which uses the digits 0 to 9 and the letters A to F.
- Nibble
- A group of 4 bits — exactly one hexadecimal digit.
- Error code
- An error message generated by the computer, often shown in hex as the memory location of the error.
- MAC address
- A 48-bit address in hex (NN-NN-NN-DD-DD-DD) that uniquely identifies a device's NIC: manufacturer code then serial number.
- IP address
- An address given to each device on a network; IPv4 is 32 bits, IPv6 is 128 bits written in hex.
- HTML colour code
- A six-digit hex value
#RRGGBBgiving the intensity of red, green and blue.
Homework 1 min
Task (≤ 15 min): (a) Convert 200 to 8-bit binary. (b) Convert that binary number to hex. (c) Convert hex 7D4 to denary. (d) Convert denary 3000 to hex. [5]
Model answer
- (a) 200 = 128 + 64 + 8 =
11001000(1) - (b)
1100 1000→C8(1) - (c) (7 × 256) + (13 × 16) + (4 × 1) = 1792 + 208 + 4 = 2004 (2)
- (d) 3000 ÷ 16 = 187 r 8; 187 ÷ 16 = 11 r 11 (B); 11 ÷ 16 = 0 r 11 (B) → BB8 (1)