Skip to content
IGCSE·Tuition
Computer Science · Lesson

Use hexadecimal as a compact representation

Hex letters such as B and F look strange until you notice they are only single digits that go beyond nine.

On this page
  1. What is the map from four bits to one hex digit?
  2. How do you convert binary to hex and back?
  3. Worked example
  4. Can you check hex conversions in code?
  5. The mistake to watch for
  6. Check yourself
  7. Where this leads next

Hexadecimal (hex) is base 16: it has sixteen digits, 0 to 9 and then A to F. Because 16 = 24, one hex digit is exactly four bits, so hex is a shorter way to write binary, not a different way for a computer to store it.

This lesson builds on converting between binary and denary and sits inside Representing numbers and text.

What is the map from four bits to one hex digit?

Four bits (a nibble) can hold 0 to 15, which is exactly the sixteen hex digits.

DenaryBinaryHexDenaryBinaryHex
000000810008
100011910019
200102101010A
300113111011B
401004121100C
501015131101D
601106141110E
701117151111F

You do not need to memorise the table. The binary column is just the 8, 4, 2, 1 place values, so you can rebuild any row in seconds.

How do you convert binary to hex and back?

Binary to hex:

  1. Split the bits into groups of four, starting from the right. Pad the left with zeros if the last group is short.
  2. Convert each group to a number from 0 to 15 using 8, 4, 2, 1.
  3. Write each number as a hex digit.

Hex to binary: replace each hex digit with its four bits.

Hex to denary: multiply the left digit by 16 and add the right digit.

Worked example

Convert 10111100 to hex, then to denary.

Step 1, group: 1011 and 1100.

Step 2, convert each group: 1011 = 8 + 2 + 1 = 11 = B. And 1100 = 8 + 4 = 12 = C.

Step 3, hex answer: BC.

Step 4, denary: B is 11 and C is 12, so 11 × 16 + 12 = 176 + 12 = 188.

Check: 10111100 in binary is 128 + 32 + 16 + 8 + 4 = 188. Both routes agree.

Going the other way, hex 3F becomes 0011 and 1111, so the binary is 00111111. In denary, 3 × 16 + 15 = 63, and 32 + 16 + 8 + 4 + 2 + 1 = 63 as well.

Can you check hex conversions in code?

Yes. In Python, hex(188) gives '0xbc', int("BC", 16) gives 188 and format(188, "08b") gives 10111100. Try them in the Python reasoning sandbox.

Use code to confirm your paper working, not to replace it, because the exam asks you to show the method.

The mistake to watch for

A common slip is grouping the bits from the left when the length is not a multiple of four.

Question: Convert 1101101 (7 bits) to hex.

Mistaken working: group from the left: 1101 and 101, so D and 5, giving D5.

D5 is 213 in denary, but 1101101 is 64 + 32 + 8 + 4 + 1 = 109. Group from the right and pad the left: 0110 1101, which is 6 and 13, so 6D. Check: 6 × 16 + 13 = 109.

Check yourself

1. Convert hex 7E to binary and denary.

Show answer

7 = 0111 and E = 14 = 1110, so the binary is 01111110. Denary: 7 × 16 + 14 = 112 + 14 = 126. Check: 64 + 32 + 16 + 8 + 4 + 2 = 126.

2. Convert 11110001 to hex.

Show answer

Groups: 1111 and 0001. 1111 = 15 = F and 0001 = 1. The answer is F1. In denary that is 15 × 16 + 1 = 241.

3. Give one reason a programmer might write 255 as FF.

Show answer

FF stands for 1111 1111, the largest 8-bit value (255). It takes two characters instead of eight, so it is shorter and easier to read and to copy without a mistake.

Where this leads next

Next, practise adding binary numbers and noticing overflow, then test the module with the mixed practice set. Hex gets quick once the four-bit groups feel automatic, and a teacher can drill that with you in online one-to-one Computer Science tuition.

Questions people ask

Why is hexadecimal used instead of binary?

Binary strings get long and easy to misread. One hex digit stands for exactly four bits, so an 8-bit byte is only two hex digits. It is shorter for humans to read and write, while the computer still stores plain binary.

What do the letters A to F mean in hex?

Hex has sixteen digits: 0 to 9, then A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. The letters are used because each digit has to be a single symbol, and 10 to 15 would otherwise need two.

Where is hexadecimal used in real life?

Common examples are colour codes in web pages, MAC addresses, memory addresses and error codes. Check your syllabus year for the examples Cambridge lists, and be ready to explain why hex suits each one.

How do I convert hex straight to denary?

Multiply the left digit by 16 and add the right digit. For 3F: 3 × 16 = 48, plus 15 gives 63. For longer values, the columns are worth 1, 16, 256 and so on, but two-digit values are the usual case.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If hexadecimal still feels like guesswork whenever a letter appears, a one-to-one teacher can rebuild the 0 to 15 mapping with you and then practise it with fresh values until it holds.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parents: enquire here

  • 9,000+ students helped through our service
  • 9+ years helping IGCSE students