GCSE Revision

Hexadecimal

What hexadecimal is

Hexadecimal (hex) is base 16. It needs 16 digits, so after 0–9 it uses the letters A–F for 10–15:

DenaryBinaryHex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

One hex digit stands for exactly 4 bits (a nibble), so a byte is always two hex digits, from 00 (0) to FF (255).

Key terms

Why programmers use hex

Computers still store everything in binary: hex is just a way for people to write it.

  • It's shorter: 11010110 is just D6.
  • It's easier to read and remember, so there are fewer mistakes when reading or typing it.
  • It converts to and from binary more easily than denary does, as each hex digit is one nibble.

You'll see hex in colour codes on web pages, such as #FF0000 for red, in MAC addresses of network cards, and in error codes.

Key terms

Hex and denary

In a two-digit hex number, the left digit is worth 16s and the right digit 1s.

Hex to denary: convert 3C.

  1. 3 × 16 = 48
  2. C is 12, so 12 × 1 = 12
  3. 48 + 12 = 60

Denary to hex: convert 200.

  1. Divide by 16: 200 ÷ 16 = 12 remainder 8
  2. The 16s digit is 12, which is C; the 1s digit is the remainder, 8
  3. So 200 is C8. Check: 12 × 16 + 8 = 200.

Key terms

Hex and binary, by nibbles

Binary to hex: split the byte into two nibbles, then convert each one using the place values 8, 4, 2, 1.

Example: convert 10101110.

Left nibbleRight nibble
Binary10101110
Denary8 + 2 = 108 + 4 + 2 = 14
HexAE

So 10101110 is AE.

Hex to binary: turn each hex digit into 4 bits, then join them. 5B: 5 is 0101 and B (11) is 1011, so 5B is 01011011.

You can also go between hex and denary through binary, if you find that easier.

Common mistake

Every hex digit becomes four bits, with leading zeros: 5 is 0101, not 101. Otherwise the bits shift into the wrong places.

Take the quiz