AQA GCSE Computer Science (8525), section 3.3.2 (Converting between number bases)
Binary and hexadecimal
One hex digit = four bits (a nibble). Convert each group of four bits separately.
Binary to hex
Split the byte into two groups of four and convert each.
1001 1100: 1001 = 9 and 1100 = 12 = C, so the hex is 9C.
Hex to binary
Convert each hex digit to four bits.
A3: A = 10 = 1010, and 3 = 0011, so the binary is 1010 0011.
| Hex digit | Binary |
|---|---|
| 0 to 9 | 0000 to 1001 |
| A | 1010 |
| B | 1011 |
| C | 1100 |
| D | 1101 |
| E | 1110 |
| F | 1111 |
Decimal and hexadecimal
The columns in a two-digit hex number are 16s and 1s.
Hex to decimal
B7: B = 11, so .
A3: .
Decimal to hex
Divide by 16. The whole number is the first digit, the remainder is the second.
Convert 200: remainder , so 12 = C and the hex is C8.
Convert 77: remainder , so 4 and D, giving 4D.
(An alternative is to convert to binary first, then to hex.)
The maximum values
| Decimal | Binary | Hex |
|---|---|---|
| 255 | 1111 1111 | FF |
Common mistake: writing hex digits above 9 as numbers, such as "12" instead of C. Also, remember that a nibble (4 bits) matches one hex digit, so 8 bits always gives two hex digits.
Exam tip: for binary to hex, split into groups of four from the right first and work out each group. Write the final answer with letters in capitals.
Check yourself
Convert 1111 0000 to hexadecimal.
F0.
Convert hex 2F to decimal.
2 × 16 + 15 = 47.
Convert decimal 100 to hexadecimal.
64 (6 × 16 + 4).