Study Guide
Hexadecimal
Why people write binary in groups of four bits as base 16, how to convert between hexadecimal, binary and denary, and where hexadecimal is used.
Lesson 1.2 Data Representation
For: Cambridge IGCSE Computer Science learners, or anyone who can already convert between binary and denary
Stage: Think
A code that is hard to read
Mia belongs to her school’s robotics club. When her robot goes wrong, its controller shows an error code as sixteen bits, and she has to read it out so that a friend can look it up in the manual. Today the screen shows this: 1011010011100001. (Mia, the club and the robot are fictional.)
Think it through
What could go wrong when Mia reads sixteen 1s and 0s aloud, and what could she do to make the code easier to say and to copy?
- Hint 1: Try copying it onto paper without looking back at the screen. Where do you lose your place?
- Hint 2: How are long phone numbers or bank card numbers usually written to make them easier to read?
Show what happens
It is easy to skip a digit, repeat one or lose the place, because every digit looks like the one before it. Splitting the code into short groups, such as 1011 0100 1110 0001, helps. The next step shows a way of splitting it that also makes it much shorter.
Stage: Discover
Four bits at a time
Mia splits her code into groups of four bits: 1011 0100 1110 0001. Look at just one group.
Think it through
How many different patterns can a group of four bits make? What are the smallest and the largest values it can hold, in denary?
- Hint 1: Each extra bit doubles the number of patterns. Start from one bit and double three times.
- Hint 2: The smallest pattern is 0000. What is the largest, and what do its columns 8, 4, 2 and 1 add up to?
Show what happens
Four bits make 2 × 2 × 2 × 2 = 16 patterns, the values 0 to 15 (0000 to 1111, which is 8 + 4 + 2 + 1 = 15).
A group of four bits is called a nibble, because it is half a byte. If every nibble is to be written as a single symbol, there must be sixteen different symbols. Denary has only ten digits, 0 to 9, so the extra six are borrowed from the alphabet: A is ten, B is eleven, C is twelve, D is thirteen, E is fourteen and F is fifteen.
Writing numbers with these sixteen symbols, where each column is worth sixteen times the column to its right, is called hexadecimal, “hex” for short, or base 16.
| Denary | Binary | Hexadecimal |
|---|---|---|
| 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 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
You do not need to memorise this table. Any row can be rebuilt from the place values 8, 4, 2 and 1: for 1101 add 8 + 4 + 1 = 13, and 13 is D.
Check your understanding
Show the answer
Answer: B. D, because 8 + 4 + 1 = 13, and D is thirteen.
1101 is 8 + 4 + 1 = 13, and the symbol for thirteen is D.
Stage: Explain
From binary to hexadecimal
Now Mia’s whole code, 1011 0100 1110 0001, can be written with one symbol for each nibble.
Think it through
Use the table to find the symbol for each of Mia’s four nibbles, and write her code in hexadecimal.
- Hint 1: Take the nibbles one at a time, left to right: 1011, then 0100, then 1110, then 0001.
Show a model answer
1011 is 11, which is B. 0100 is 4. 1110 is 14, which is E. 0001 is 1. The code is B4E1: four symbols instead of sixteen digits.
- Split the binary number into nibbles. It is already split: 1001, 1100 and 0111.
- Work out each nibble’s value. 1001 is 8 + 1 = 9. 1100 is 8 + 4 = 12. 0111 is 4 + 2 + 1 = 7.
- Write each value as one hexadecimal symbol. 9 is 9, 12 is C and 7 is 7.
- Join the symbols in the same order. The answer is 9C7.
- Check by converting back. 9C7 is 9 × 256 + 12 × 16 + 7 = 2304 + 192 + 7 = 2503, and 100111000111 in binary is 2048 + 256 + 128 + 64 + 4 + 2 + 1 = 2503. The two agree.
Each nibble is converted on its own, because four bits is exactly one hexadecimal digit. There is no carrying from one nibble to the next.
First try some with the first row worked for you.
| Binary | Hexadecimal |
|---|---|
| 0011 1110 | 3E |
| 1001 0101 | |
| 1100 1111 | |
| 0000 1011 1000 0001 | |
| 1111 1111 1111 1111 |
- Find the value of each nibble first, then the symbol for that value.
- Keep the nibbles in the same order, left to right.
Show the completed table
| Binary | Hexadecimal |
|---|---|
| 0011 1110 | 3E |
| 1001 0101 | 95 |
| 1100 1111 | CF |
| 0000 1011 1000 0001 | 0B81 |
| 1111 1111 1111 1111 | FFFF |
Stage: Discover
When the bits do not split into fours
Think it through
The binary number 101101 has six bits, but nibbles need four. Should you start making groups of four from the left or from the right? What do you do about the bits left over?
- Hint 1: Think about 0325 and 325: which end of a number can you add extra zeros to without changing its value?
Show what happens
Start from the right. Zeros can be added to the front of a number without changing it, just as 0325 is still 325. So 101101 splits as 10 | 1101, and the short group is filled out to 0010. Then 0010 is 2 and 1101 is D, so the number is 2D.
Check your understanding
Show the answer
Answer: C. 6D, from the groups 0110 and 1101, starting from the right.
Group from the right: 110 | 1101. Fill the short group out to 0110. 0110 is 6 and 1101 is D, so 1101101 is 6D.
Stage: Predict
From hexadecimal back to binary
Mia’s friend finds a code in the manual: 2F9C. To compare it with the robot’s memory, she needs it in binary.
Think it through
Using what you know about nibbles, how could you turn 2F9C back into binary? Write down your plan and then try it.
- Hint 1: Each hexadecimal digit stands for one nibble. What are the four bits for each of 2, F, 9 and C?
Now try it for yourself, with the first row worked.
| Hexadecimal | Binary |
|---|---|
| A5 | 1010 0101 |
| 2F | |
| C3 | |
| 90 | |
| 1B7C |
- Write four bits for every symbol, even when they begin with 0s.
- Work out a symbol’s value first if you need to, then use the columns 8, 4, 2 and 1.
Show the completed table
| Hexadecimal | Binary |
|---|---|
| A5 | 1010 0101 |
| 2F | 0010 1111 |
| C3 | 1100 0011 |
| 90 | 1001 0000 |
| 1B7C | 0001 1011 0111 1100 |
Stage: Discover
Hexadecimal and denary
So far hexadecimal has gone through binary. It can also be converted to denary directly, by thinking about its columns.
Think it through
In denary the columns from the right are worth 1, 10 and 100: each is ten times the one before. In binary they are 1, 2, 4 and 8: each is twice the one before. What would you expect the first four columns of a base 16 number to be worth?
- Hint 1: Each column is worth sixteen times the column on its right. Start from 1.
Show what happens
1, 16, 256 and 4096: 1 × 16 = 16, 16 × 16 = 256 and 256 × 16 = 4096.
Hexadecimal to denary: 1A7.
- Write the column values above the digits: 256, 16 and 1.
- Turn each symbol into its value. 1 is 1, A is ten and 7 is 7.
- Multiply each value by its column and add. 1 × 256 + 10 × 16 + 7 × 1 = 256 + 160 + 7 = 423.
Denary to hexadecimal: 183.
- Divide by 16 and keep the remainder. 183 ÷ 16 = 11 remainder 7. The remainder 7 is the right-hand digit, because it is the part that is not a whole sixteen.
- Divide the answer again. 11 ÷ 16 = 0 remainder 11. Eleven is B, the next digit to the left. The answer has reached 0, so stop.
- Read the remainders from last to first. B then 7, so 183 is B7.
- Check. B7 is 11 × 16 + 7 = 176 + 7 = 183.
A second route gives the same answer: 183 is 10110111 in binary, which is 1011 0111, which is B7.
A 16-bit number has columns worth 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 and 32768. Splitting it into four nibbles and converting through hexadecimal is often quicker than adding up sixteen columns.
Converting directly works too, exactly as for 8 bits: add the values of the columns that hold a 1, or, from denary, take away the largest column value that fits and carry on with what is left.
| 16-bit binary | Denary |
|---|---|
| 0000 0001 0000 0001 | |
| 0010 0000 0000 0000 | |
| 1000 0000 0000 0001 | |
| 1000 | |
| 40000 |
- Write the sixteen column values above the bits, from 32768 on the left to 1 on the right.
- From denary: subtract the largest column value that fits, write a 1 there, and repeat with the remainder.
Show the completed table
| 16-bit binary | Denary |
|---|---|
| 0000 0001 0000 0001 | 257 |
| 0010 0000 0000 0000 | 8192 |
| 1000 0000 0000 0001 | 32769 |
| 0000 0011 1110 1000 | 1000 |
| 1001 1100 0100 0000 | 40000 |
Do not confuse: The same symbols, three different numbers
- In denary10
- ten1 × 10 + 0 × 1
- In binary10
- two1 × 2 + 0 × 1
- In hexadecimal10
- sixteen1 × 16 + 0 × 1
To avoid confusion, a small number can show the base: 10₂ is binary, 10₁₆ is hexadecimal. Some programming languages write a hexadecimal number with 0x in front, and web colours use a # sign.
| Binary | Hexadecimal | Denary |
|---|---|---|
| 0010 1111 | 2F | 47 |
| 1100 1000 | ||
| 5A | ||
| 255 | ||
| B7 | ||
| 0001 0000 0000 0000 |
- Choose whichever route you like: through binary, or with the column values 16 and 1.
- Check each answer by converting it back.
Show the completed table
| Binary | Hexadecimal | Denary |
|---|---|---|
| 0010 1111 | 2F | 47 |
| 1100 1000 | C8 | 200 |
| 0101 1010 | 5A | 90 |
| 1111 1111 | FF | 255 |
| 1011 0111 | B7 | 183 |
| 0001 0000 0000 0000 | 1000 | 4096 |
Check your understanding
Show the answer
Answer: A. 124, from 7 × 16 + 12 × 1.
7 × 16 = 112, and C is twelve, so 7C = 112 + 12 = 124.
Stage: Explain
Why people use hexadecimal
Think it through
A 16-bit value could be written in binary (sixteen digits), in denary (up to five digits) or in hexadecimal (four digits). Which would you choose for people who must read it out, copy it and remember it? Which one lets you find the underlying bits most easily? Explain your choices.
- Hint 1: Compare how long each is. Then try to write the bits of 4F2A, and of 20,266 (the same number in denary).
Show a model answer
Hexadecimal is much shorter than binary, which makes it easier to read, say, write down and remember, and means fewer mistakes. It also lines up exactly with the bits: every symbol is one nibble, so the binary can be written straight from it. Denary is short, but its columns do not line up with bits, so converting means arithmetic. For example 4F2A is 0100 1111 0010 1010 at once, but nothing in 20,266 shows the bits.
Hexadecimal is used because it is easier for people than long binary. It is not used because computers prefer it. It is shorter, so it is easier to read, write and remember, it leads to fewer errors, and it converts to and from binary exactly, one symbol per nibble.
Where it appears, with invented examples:
| Where it is used | What it looks like | Why hexadecimal helps |
|---|---|---|
| MAC addresses (the 48-bit address of a network device) | 3C:5A:B4:1F:90:7E | Forty-eight bits would be 48 digits. In hexadecimal it is 12 symbols, written as 6 pairs, one pair per byte. |
| Error messages and error codes | Error 0x00A3 | A short code is easy to type into a search or quote to a helpdesk. |
| HTML colour codes | #FF8000 | Three pairs give the red, green and blue amounts, each from 00 to FF (0 to 255). Here FF is 255, 80 is 128 and 00 is 0: orange. |
| Memory dumps (a printout of what is stored in memory) | 3C 7F 00 A9 | Each byte is exactly two symbols, so the printout stays neat and each byte can be read quickly. |
| IPv6 addresses (128-bit internet addresses) | 2001:0DB8:85A3:0000:0000:8A2E:0370:7334 | A 128-bit address is eight groups of four symbols. In binary it would be 128 digits. |
Hexadecimal is only a way of writing bits for people. Inside the computer the value is still stored as bits: 4F2A takes exactly the same memory as 0100 1111 0010 1010. It is not encrypted, not compressed, and not stored differently.
Check your understanding
Show the answer
Answer: C. It is shorter for people to read and copy, and each symbol is exactly four bits.
Hexadecimal is for people. Four symbols are easier to read, copy and remember than sixteen digits, and each symbol converts to exactly four bits.
Stage: Apply
Use it somewhere new
A school’s web page uses the background colour code #00A0FF. The three pairs of symbols are the amounts of red (00), green (A0) and blue (FF), each from 0 to 255.
Apply it
Show the answer
Answer: B. 160, because A is in the sixteens column: 10 × 16 + 0.
A0 = 10 × 16 + 0 × 1 = 160.
A fictional rain gauge sends its reading as a 16-bit pattern: 0000 0011 1110 1000.
Apply it
Show the answer
Answer: D. 1000, because the pattern is 03E8: 3 × 256 + 14 × 16 + 8.
The nibbles are 0000 (0), 0011 (3), 1110 (E) and 1000 (8), so the pattern is 03E8. Then 3 × 256 + 14 × 16 + 8 × 1 = 768 + 224 + 8 = 1000.
Apply it
Show the answer
Answer: A. He wrote the nibbles in the wrong order: 1010 is A and 1111 is F, so it is AF.
1010 is A and 1111 is F, so the answer is AF. Leo’s FA is a different number: 15 × 16 + 10 = 250 instead of 10 × 16 + 15 = 175.
Stage: Consolidate
Bring it together
Think it through
Without looking back, explain to a friend how you would convert the hexadecimal number 3C to binary and to denary, and why hexadecimal is used at all.
Show a model answer
For binary, turn each symbol into a nibble: 3 is 0011 and C (twelve) is 1100, so 3C is 0011 1100. For denary, use the columns 16 and 1: 3 × 16 + 12 = 60. Hexadecimal is used because it is a shorter, more readable way for people to write binary, with fewer mistakes, and it converts to bits exactly, one symbol per nibble.
Check your understanding
Show the answer
Answer: B. 65,535, because FFFF has every one of the sixteen bits set to 1.
FFFF is 15 × 4096 + 15 × 256 + 15 × 16 + 15 = 61,440 + 3,840 + 240 + 15 = 65,535, the same as 16 bits all on.
- A group of four bits is a nibble. It has 16 patterns, so it can be written as one hexadecimal (base 16) digit: 0 to 9, then A to F for ten to fifteen.
- To convert binary to hexadecimal, split into nibbles starting at the right, filling the first with leading zeros if needed, and write one symbol for each. To go back, write four bits for each symbol.
- To convert hexadecimal to denary, multiply each symbol’s value by its column: 1, 16, 256, 4096. To go from denary to hexadecimal, divide by 16 repeatedly and read the remainders from last to first, or go through binary.
- Hexadecimal 10 is sixteen, not ten.
- Hexadecimal is used because it is easier for people to read, write and remember than binary, with fewer errors, for example in MAC addresses, error messages, HTML colour codes, memory dumps and IPv6 addresses. Inside the computer the data is still bits.
Sources and scope
- What this lesson is. The second lesson of the Data Representation module, written for this site. It teaches the hexadecimal part of Cambridge IGCSE Computer Science 1.1, points 2 and 3, with the same sections of the 2026 to 2028 syllabus (version 6) used for its curriculum links. Those links are provisional: no link has been verified by the site owner, and they show where the lesson may help with a course. They imply no review or endorsement by any examination board.
- Original material. Mia, her robotics club and her robot, the rain gauge, the school web page and its colour code, the MAC address, the error code and the memory-dump line are fictional examples written for this lesson. The IPv6 address is a documentation example reserved for use in books and guides.
- Simplified on purpose. Conversion is for positive whole numbers only, up to 16 bits and four hexadecimal digits. Negative numbers are in the lesson on two’s complement. Real error codes and memory dumps are longer and use more conventions than the short invented ones shown here.
The number system with only two digits, 0 and 1, in which each column is worth twice the column to its right.
A single binary digit: 0 or 1. The smallest unit of data a computer stores.
A group of eight bits, which can hold one of 256 different patterns.
The everyday number system with ten digits, 0 to 9, in which each column is worth ten times the column to its right.
The number system with sixteen digits, 0 to 9 and then A to F, in which each column is worth sixteen times the column to its right.
The language in which the structure and content of a web page is written, which a browser renders into the page you see.
A group of four bits, half a byte, which can hold one of 16 patterns and so can be written as one hexadecimal digit.
What a digit is worth because of the column it is in: the 2 in 325 is worth twenty, not two.
A way of storing positive and negative whole numbers in binary, in which the left-hand bit is worth a negative amount (−128 in an 8-bit number).
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.