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 usedExample
Memory addresses0x1A3F — far more readable than 16 binary digits
Colour codes (HTML/CSS)#FF5733 — three 8-bit colour channels in 6 hex digits
Machine code / assembly listingsInstructions and operands displayed as hex bytes
MAC addresses and IPv62001:0db8:85a3::8a2e
Error codes0x0000007E — 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.

HexDenaryBinary (4 bits)HexDenaryBinary
000000881000
110001991001
220010A101010
330011B111011
440100C121100
550101D131101
660110E141110
770111F151111

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.