AQA 7517, section 4.5.2.1
A number base (or radix) tells you how many different digits a number system uses, and what each place is worth. We normally use base 10, but computers work in base 2, and people often use base 16 as a shorthand for binary.
The three bases
| Base | Name | Digits used | Place values (from the right) |
|---|---|---|---|
| 10 | Decimal | 0 to 9 | 1, 10, 100, 1000, ... |
| 2 | Binary | 0 and 1 | 1, 2, 4, 8, 16, ... |
| 16 | Hexadecimal | 0 to 9, A to F | 1, 16, 256, 4096, ... |
Hexadecimal needs six extra digits: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
Writing the base
The base is written as a subscript after the number:
- Base 10:
- Base 2:
- Base 16:
Without a subscript, a number such as 101 is ambiguous: it could be one hundred and one, or five in binary.
Binary to decimal
Add the place values wherever there is a 1.
Decimal to binary
Method 1: work down the place values. Write 1 if the value fits and subtract it, otherwise write 0.
Convert 77 to binary. 64 fits (13 left), 32 doesn't, 16 doesn't, 8 fits (5 left), 4 fits (1 left), 2 doesn't, 1 fits.
Method 2: divide by 2 repeatedly and read the remainders from bottom to top.
| Divide | Quotient | Remainder |
|---|---|---|
| 38 | 1 | |
| 19 | 0 | |
| 9 | 1 | |
| 4 | 1 | |
| 2 | 0 | |
| 1 | 0 | |
| 0 | 1 |
Reading the remainders from the bottom gives , which is in 8 bits.
Hexadecimal
Each hex digit stands for exactly four bits, because . This makes conversion between binary and hex quick.
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Binary to hex
Split the binary into groups of four starting from the right, then convert each group.
because and .
Hex to binary
Replace each hex digit with its four bits:
Hex to decimal
Multiply each digit by its place value (, , ...):
Decimal to hex
Divide by 16 repeatedly, reading the remainders from bottom to top. For 300:
| Divide | Quotient | Remainder |
|---|---|---|
| 18 | 12 (C) | |
| 1 | 2 | |
| 0 | 1 |
Check: .
Why is hexadecimal used?
Hexadecimal is used as a shorthand for binary:
- Long binary strings are hard to read and easy to copy wrongly. Hex is four times shorter:
1011 0111becomesB7. - Converting between binary and hex is simple, because each hex digit is exactly four bits.
- It is used for memory addresses, colour codes (such as
#FF8800), MAC addresses and error codes.
It is not faster for the computer, which still works entirely in binary. Hex is purely for human convenience.
Worked example
Task: convert to decimal and to hexadecimal.
- Decimal: .
- Hex: split into nibbles and . and , so the answer is .
- Check: . ✓
Exam tip: write the base as a subscript, and show your working. When giving the reason for using hex, say that it is a shorter and easier-to-read way of writing binary, and not that it is faster for the computer.
Check yourself
Convert to decimal
.
Convert 200 to binary and to hexadecimal
. Split into and , giving .
How many bits does one hex digit represent?
Four bits.
Why do programmers use hexadecimal instead of binary?
It is a shorter, more readable way to write binary values, and it converts to and from binary easily.