Hexadecimal

GCSE Computer Science (Edexcel) · Edexcel 1CP2 · 2.1.6 · Data › Binary

66 exam-style questions plus unlimited generated ones on this topic, at up to four difficulty levels, with full mark schemes. Notes and past-paper booklets are open to everyone. Practice needs a free account.

Or take a quick quiz: 10 questions on this subtopic in GCSE Computer Science (Edexcel), marked as you tap.

Revision notes

Why hexadecimal (base 16) is used, and how to convert between hexadecimal and binary. Expect 1-mark conversions and 2-mark 'explain why hexadecimal is used' questions.

Key facts

  • Hexadecimal = base 16: digits 0⁠–⁠9 and A⁠–⁠F
  • A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
  • 1 hex digit = 4 bits (1 nibble); 2 hex digits = 1 byte
  • Nibble place values: 8 4 2 1
  • 00 = 0000 0000 and FF = 1111 1111
  • Hex is used because it is shorter and easier for people to read and copy than binary
  • Computers store everything in binary, never in hex

Notes

What hexadecimal is

  • Hexadecimal (hex) is base 16. It uses 16 digits: 0 to 9, then A (10), B (11), C (12), D (13), E (14) and F (15).
  • One hex digit stands for exactly 4 bits (a nibble), because 4 bits give 24 = 16 patterns, from 0000 (0) to 1111 (F).
  • So one byte (8 bits) is always exactly 2 hex digits, from 00 to FF.

Why it is used

  • Computers do not store data in hex: everything is still stored in binary. Hex is a shorthand for people.
  • It is much shorter: 1101 0111 1010 0011 is written as D7A3.
  • So it is easier to read, remember and type, and people are less likely to make mistakes when copying it.
  • It converts to and from binary easily, one digit for each nibble.
  • You will see it used for things such as colour codes, memory addresses and error codes.

Converting

diagram
  • Binary to hex: split the bits into nibbles, starting from the right, then convert each nibble using the place values 8, 4, 2, 1. 1011 0110: 1011 = 8 + 2 + 1 = 11 = B and 0110 = 4 + 2 = 6, so B6.
  • 84218421101101108 + 2 + 1 = 114 + 2 = 6B6so the hex is B6
    One hex digit for each nibble (4 bits): 1011 0110 = B6
  • Hex to binary: write each digit as a 4-bit pattern. 3F: 3 = 0011 and F = 1111, so 0011 1111.
  • Keep the leading 0s in each nibble: 3 is 0011, not 11.
  • If the number of bits is not a multiple of 4, add 0s on the left first: 10 1101 becomes 0010 1101, which is 2D. Grade 7+ only
  • To find a denary value, go through binary: 3F = 0011 1111 = 32 + 16 + 8 + 4 + 2 + 1 = 63. (Or 3 × 16 + 15 = 63.) Grade 6+ only

How to answer each type of question

Convert between binary and hexadecimal

1 mark eachGrade 5
  1. Split the binary into groups of 4 bits, starting from the right.
  2. Convert each group using the place values 8, 4, 2, 1.
  3. Write the values 10 to 15 as A to F.
  4. For hex to binary, write 4 bits for every digit, keeping leading 0s.

Example. (a) Convert the 8-bit binary number 1110 0101 to hexadecimal.
(b) Convert the hexadecimal number 9C to 8-bit binary.

Show the model answerHide the model answer
(a) E5
(1)
(1110 = 14 = E and 0101 = 5)
(b) 1001 1100
(1)
(9 = 1001 and C = 12 = 1100)

Explain why hexadecimal is used

2 marksGrade 6
  1. Make the first point: hex is shorter (1 digit for every 4 bits).
  2. Make a second, separate point: so it is easier for people to read, remember or type, with fewer errors.
  3. Use the context if there is one (addresses, colour codes).

Example. A web designer writes 24-bit colour codes in hexadecimal.
Explain why hexadecimal is used instead of binary.

Show the model answerHide the model answer
Each colour is written with 6 hex digits instead of 24 bits, so it is much shorter (1). This makes it easier to read, remember and type, with less chance of a copying mistake (1).

Convert a 16-bit value

2 marksGrade 7
  1. Split the 16 bits into four nibbles.
  2. Convert each nibble to one hex digit.
  3. Check that the answer has exactly 4 hex digits.

Example. A memory address is shown as the 16-bit binary value 0101 1110 0000 1011.
Convert it to hexadecimal.

Show the model answerHide the model answer
5E0B
First two digits 5E (1); last two digits 0B
(1)

Explain a misconception about hexadecimal

2 marksGrade 8
  1. Say that computers store all data in binary.
  2. Say that hex is only a way of displaying or writing the value for people.
  3. Say that the value uses the same number of bits either way.

Example. A technician says that storing memory addresses in hexadecimal instead of binary will free up space in memory.
Explain why the technician is wrong.

Show the model answerHide the model answer
The computer stores all data, including addresses, in binary (1). Hexadecimal is only a way of displaying the value to people, so the address takes up the same number of bits however it is written (1).

Don’t lose marks

  • Converting the whole byte to denary and writing that, e.g. 229 instead of E5.
  • Writing a two-digit number such as 14 inside a hex answer instead of the letter E.
  • Dropping the leading 0s of a nibble: 5A is 0101 1010, not 101 1010.
  • Saying hex is used 'because computers understand it' or 'to save memory'. It is for people; computers only use binary.
  • Grouping bits from the left when the number of bits is not a multiple of 4.

More tips

Memory tricks

  • Learn the nibble table once: 1010 = A, 1011 = B, 1100 = C, 1101 = D, 1110 = E, 1111 = F.
  • Count on from A = 10: A10, B11, C12, D13, E14, F15.
  • Sense check: 8 bits always give exactly 2 hex digits, and every hex digit gives exactly 4 bits.
  • F is the largest digit, so FF = 1111 1111 = 255, the largest value one byte can hold.

Exam technique

  • In 'explain why hex is used', make two separate points: it is shorter, AND so it is easier for people to read and less error-prone.
  • Show the nibble split in your working (1110 | 0101), so a slip in one digit is easy to spot when you check.
  • Double-check your letters: B (11) and D (13) are easy to mix up.

What each grade needs

What you need to be able to do, from the first marks up to the top grade.

  1. Grade 4
    Recall the hex digits 0⁠–⁠9 and A⁠–⁠FA = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
  2. Grade 4
    State that one hex digit is 4 bits16 different digits need 4 bits, because 24 = 16.
  3. Grade 5
    Convert 8-bit binary to hexadecimalSplit the bits into two nibbles and convert each nibble to one hex digit.
  4. Grade 5
    Convert hexadecimal to 8-bit binaryConvert each hex digit to its 4-bit pattern and join the patterns together.
  5. Grade 6
    Explain why hexadecimal is usedIt is shorter and easier for people to read, remember and copy than binary, and it converts to binary easily.
  6. Grade 7
    Convert longer binary and hex valuesGroup the bits in fours from the right: each group is one hex digit, so 16 bits are 4 hex digits.
  7. Grade 8
    Explain that hex does not save memoryThe computer still stores the value in binary; hex is only the way it is shown to people.

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

State the number of bits represented by one hexadecimal digit.
4
A computer displays 16-bit memory addresses in hexadecimal. One address is 4A2F. Convert 4A2F to 16-bit binary.
0100 1010 0010 1111
State the number of hexadecimal digits needed to write a 48-bit MAC address.
12
A microcontroller kit shows the value of each 8-bit sensor reading as a 2-digit hexadecimal number. Convert the hexadecimal reading 2F to 8-bit binary.
0010 1111
Complete the sentences. A byte contains ……… bits. A byte can be written using ……… hexadecimal digits.
8, 2
A program stores the 16 hexadecimal digits in a string.
digits = "0123456789ABCDEF"
State the output of this line.
print(digits[10])
A

Sample questions

Written for this site in the style of Edexcel exam questions. They are not taken from real past papers.

Question 1Easy3 marks
(a) State the number of bits represented by one hexadecimal digit.
[1]
(b) Give the denary value of the hexadecimal digit D.
[1]
(c) Convert the 8-bit binary number 1010 0111 to hexadecimal.
[1]
Show the answer and mark scheme
(a) Answer: 4
  • 4
(b) Answer: 13
  • 13
(c) Answer: A7
  • hexadecimal A7
Question 2Medium4 marks
The display on a network router shows error codes in hexadecimal.
(a) Convert the error code 3E to 8-bit binary.
[1]
(b) Convert the 8-bit binary number 1100 0101 to hexadecimal.
[1]
(c) A student says, 'Storing the error codes in hexadecimal takes up less memory than storing them in binary.'
Explain why the student is wrong.
[2]
Show the answer and mark scheme
(a) Answer: 0011 1110
  • 0011 1110
(b) Answer: C5
  • hexadecimal C5
(c) Answer: The computer always stores the code in binary; hexadecimal is only how it is shown to people, so the memory used is the same.
  • computers store all data in binary; hexadecimal is only a way of displaying / writing the values for people
  • 3E and 0011 1110 are the same value and take up the same 8 bits of memory
Question 3Hard5 marks
A computer displays 16-bit memory addresses in hexadecimal. One address is 4A2F.
(a) Convert 4A2F to 16-bit binary.
[2]
(b) Explain why hexadecimal is used to display memory addresses instead of binary.
[2]
(c) State the largest 16-bit memory address, in hexadecimal.
[1]
Show the answer and mark scheme
(a) Answer: 0100 1010 0010 1111
  • first 8 bits: 0100 1010
  • last 8 bits: 0010 1111
(b) Answer: 4 hex digits instead of 16 bits: easier to read and copy correctly, and each digit maps straight to 4 bits.
  • a 16-bit address needs only 4 hexadecimal digits instead of 16 binary digits
  • so it is easier to read and remember and less likely to be copied incorrectly, while each digit still converts directly to 4 bits
(c) Answer: FFFF
  • FFFF

More in Binary

Stuck? Get 1-to-1 help.

Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.