Convert between bases
Converting Between Number Bases
This benchmark brings together all six conversion directions across the three number bases used in computer science: binary (base 2), decimal (base 10), and hexadecimal (base 16). AQA requires you to convert in both directions between all three pairings, working within the range 00000000 to 11111111 in binary, 0 to 255 in decimal, and 00 to FF in hexadecimal.
The three tabs below summarise both directions for each pairing, including the key technique that makes binary-to-hex conversion fast: treating each group of four bits independently.
Binary → Decimal
Write the 8-bit column headings (128, 64, 32, 16, 8, 4, 2, 1). Add together every column value where the bit is 1. Columns with 0 contribute nothing.
Example: convert 10110101.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
128 + 32 + 16 + 4 + 1 = 181.
Decimal → Binary
Work through the column headings from left to right. At each column, ask: does the remaining value fit? If yes, place a 1 and subtract that column's value. If no, place a 0 and move on.
Example: convert 219 to binary.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
219 → 219-128=91 → 91-64=27 → 32 too large → 27-16=11 → 11-8=3 → 4 too large → 3-2=1 → 1-1=0. Result: 11011011.
Binary → Hex (Divide & Conquer)
Because one hex digit represents exactly four binary bits, you never need to convert the full 8-bit number in one step. Split the binary number into two groups of four bits, convert each group independently (maximum value 15 per group), then replace any value of 10 or above with the letter A-F.
Example: convert 11001110.
- Split:
1100|1110. - Left group: 8+4 = 12 =
C. - Right group: 8+4+2 = 14 =
E. - Result:
CE.
Hex → Binary (Divide & Conquer)
Reverse the process: replace each hex digit with its 4-bit binary equivalent. Always write all four bits per group, including any leading zeros within the group.
Example: convert A7.
- A = 10 →
1010. - 7 →
0111. - Result:
10100111.
111 instead of 0111 shifts the left group one place and gives a completely wrong answer.
Decimal → Hex
Divide the decimal number by 16. The quotient (whole number result) is the left hex digit; the remainder is the right hex digit. Replace any value of 10 or above with the letter A-F.
Example: convert 200. 200 ÷ 16 = 12 remainder 8. Left digit = 12 = C. Right digit = 8. Result: C8.
Hex → Decimal
Multiply the left digit by 16 and the right digit by 1, then add. Always convert any letter digit to its decimal value (A=10 through F=15) before multiplying.
Example: convert B4. B = 11. 11 × 16 = 176. 4 × 1 = 4. 176 + 4 = 180.
Choosing Your Route: Direct or Via Binary
Binary-to-hex and hex-to-binary use the Divide & Conquer method (no arithmetic needed). All conversions involving decimal require working through place values or division. When asked to convert between decimal and hex, you can go directly using the methods above, or convert via binary as an intermediate step - both routes give the same result. Use whichever you find more reliable under exam conditions.
| Conversion | Method | Key operation |
|---|---|---|
| Binary → Decimal | Column place values | Add active columns |
| Decimal → Binary | Column subtraction | Subtract largest fitting power |
| Binary → Hex | Divide & Conquer (4-bit groups) | Convert each nibble independently |
| Hex → Binary | Divide & Conquer (4-bit groups) | Substitute each digit with 4 bits |
| Decimal → Hex | Divide by 16 | Quotient = left digit, remainder = right |
| Hex → Decimal | Place value × 16 and × 1 | Convert letters first, then multiply and add |
Key Takeaways
- All six conversions stay within the range 0-255: binary
00000000-11111111, decimal 0-255, hex00-FF. - Binary ↔ Hex uses the Divide & Conquer technique: one hex digit = exactly four bits. Split the byte into two nibbles and convert each independently.
- Binary → Decimal: add the column values wherever a 1 appears. Decimal → Binary: subtract the largest fitting column value repeatedly.
- Decimal → Hex: divide by 16; quotient is left digit, remainder is right digit. Hex → Decimal: multiply left digit by 16, right digit by 1, then add.
- Always convert hex letter digits (A-F) to their decimal values before multiplying by a place value, and always maintain four bits per group in hex-to-binary conversions.
- Verify any conversion by converting the result back to the original base - if the two-way trip gives the starting value, the answer is correct.