2.1.6 Hexadecimal
Why Hexadecimal?
Hexadecimal (base 16, abbreviated "hex") uses sixteen digits: 0–9 and A–F (where A=10, B=11, C=12, D=13, E=14, F=15). It is used in computing because it provides a compact, human-readable way to represent binary data.
One hexadecimal digit represents exactly four binary bits (a nibble). This means 8-bit bytes are expressed as just two hex digits, 16-bit values as four, and so on — far more readable than a long binary string.
| Where hex is used | Example |
|---|---|
| Memory addresses | 0x1A3F — far more readable than 16 binary digits |
| Colour codes (HTML/CSS) | #FF5733 — three 8-bit colour channels in 6 hex digits |
| Machine code / assembly listings | Instructions and operands displayed as hex bytes |
| MAC addresses and IPv6 | 2001:0db8:85a3::8a2e |
| Error codes | 0x0000007E — Windows BSOD codes |
Converting Between Hexadecimal and Binary
Because 16 = 24, conversion between hex and binary is direct — each hex digit maps to exactly four binary bits.
| Hex | Denary | Binary (4 bits) | Hex | Denary | Binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | A | 10 | 1010 |
| 3 | 3 | 0011 | B | 11 | 1011 |
| 4 | 4 | 0100 | C | 12 | 1100 |
| 5 | 5 | 0101 | D | 13 | 1101 |
| 6 | 6 | 0110 | E | 14 | 1110 |
| 7 | 7 | 0111 | F | 15 | 1111 |
Group the binary number into nibbles (4 bits) from the right. Convert each nibble independently to its hex digit.
Example: 10110111 01001110 → hex
1011 = B 0111 = 7 0100 = 4 1110 = E
Result: B74E
Replace each hex digit with its 4-bit binary equivalent. Always write all four bits — including leading zeros.
Example: 3F → binary
3 = 0011 F = 1111 Result: 00111111
Example: A9 → binary
A = 1010 9 = 1001 Result: 10101001
Key Takeaways
- Hexadecimal uses 16 digits: 0–9 and A–F. One hex digit = 4 binary bits (one nibble).
- Hex is used in computing because it is more compact and readable than binary.
- Binary → hex: split into groups of 4 from the right; convert each group.
- Hex → binary: expand each hex digit to 4 bits, always keeping leading zeros.