The hexadecimal number system is base . It uses sixteen distinct digit symbols: and then for values through .
Hex is everywhere in computing because it lines up cleanly with binary: every hex digit corresponds to exactly bits (). Reading or writing memory addresses, machine code, byte values — anything binary that’s more than a few bits — is easier in hex than in binary.
Hex digit table
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Notation
Hex literals are typically prefixed to mark the base:
0xFF— common in C, JavaScript, Python.\$FFor#FF— assembly.- — math notation.
The prefix is purely a label; the value is the same regardless of how you write it. .
Conversion to decimal
Standard positional expansion: each hex digit times its place value.
Conversion to/from binary
The killer feature of hex: every digit is exactly 4 bits. To convert hex → binary, replace each hex digit with its 4-bit pattern. Concatenate the results — no decimal in the middle.
To go binary → hex, group the bits into chunks of 4 starting from the right (the radix point), then map each chunk to its hex digit.
If the leftmost group is short, pad with leading zeros: .
Why it’s useful
Three places hex shows up constantly:
-
Memory addresses. A 32-bit address has 8 hex digits — much easier to read and write than 32 binary digits.
-
Byte values. Each byte fits in 2 hex digits ( to ). Color codes (
#FF8800), MAC addresses (AA:BB:CC:DD:EE:FF), checksums — all conventional in hex. -
Bit patterns in code. When you need a specific 32-bit constant in software, writing
0xFFFF0000is far less error-prone than writing .
For the general theory of converting between any two bases, see Base Conversion.