Hexadecimal – “hex” for short – is a base-16 number system used everywhere in computing: memory addresses, color codes, Unicode, and network MAC addresses. It exists for one simple reason: it makes long binary strings readable. This guide explains how hex works, why programmers love it, and how to convert between hex, binary, and decimal.
Why Base-16?
Binary is precise but painfully long – a single byte needs 8 digits (11010110). Decimal is compact but doesn’t align with binary’s structure. Hexadecimal sits in the sweet spot:
- One hex digit = exactly 4 bits (because 2⁴ = 16)
- A byte (8 bits) = exactly 2 hex digits
- Converting between binary and hex is trivial – no math required
Hex uses digits 0-9 plus letters A-F for values 10-15:
| Hex | Decimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Where You See Hex Every Day
- Web colors: `#FF5733` – FF = 255 red, 57 = 87 green, 33 = 51 blue
- Memory addresses: `0x7FFD4A2C` in debuggers (the `0x` prefix marks hex)
- Unicode: U+1F600 (😀) – the code point is written in hex
- MAC addresses: `AA:BB:CC:DD:EE:FF` on network hardware
- Error codes: `0x80070005` in Windows
Hex to Decimal: Worked Examples
Each hex position is a power of 16, from 16⁰ = 1 on the right:
0x2F:
- F = 15 in the 1s place: 15 × 1 = 15
- 2 in the 16s place: 2 × 16 = 32
- Total: 32 + 15 = 47
0xA5:
- 5 × 1 = 5
- A = 10, so 10 × 16 = 160
- Total: 160 + 5 = 165
0x100:
- 0 × 1 = 0, 0 × 16 = 0
- 1 × 256 = 256
- Total: 256 – one more than a byte can hold, which is why programmers notice it
The Effortless Binary ↔ Hex Trick
Because 4 bits = 1 hex digit, you convert by grouping – no arithmetic:
Binary 11010110 → hex:
- Group into fours from the right: `1101 0110`
- Look up each group: 1101 = D, 0110 = 6
- Result: 0xD6
Hex 0x4A → binary:
- Expand each digit: 4 = 0100, A = 1010
- Result: 01001010
Check: 0x4A = 4×16 + 10 = 74, and 01001010 = 64 + 8 + 2 = 74. ✓
This trick is why hex exists – try doing that conversion in decimal and you’ll see the difference. Our binary converter shows binary, hex, and decimal together so you can see the mapping live.
Hex, Binary, and Decimal Side by Side
Here’s a compact reference showing all three systems for the values 0-32. Programmers keep a table like this handy when debugging:
| Dec | Hex | Binary | Dec | Hex | Binary |
|---|---|---|---|---|---|
| 0 | 0x00 | 00000000 | 17 | 0x11 | 00010001 |
| 1 | 0x01 | 00000001 | 18 | 0x12 | 00010010 |
| 2 | 0x02 | 00000010 | 19 | 0x13 | 00010011 |
| 3 | 0x03 | 00000011 | 20 | 0x14 | 00010100 |
| 4 | 0x04 | 00000100 | 21 | 0x15 | 00010101 |
| 5 | 0x05 | 00000101 | 22 | 0x16 | 00010110 |
| 6 | 0x06 | 00000110 | 23 | 0x17 | 00010111 |
| 7 | 0x07 | 00000111 | 24 | 0x18 | 00011000 |
| 8 | 0x08 | 00001000 | 25 | 0x19 | 00011001 |
| 9 | 0x09 | 00001001 | 26 | 0x1A | 00011010 |
| 10 | 0x0A | 00001010 | 27 | 0x1B | 00011011 |
| 11 | 0x0B | 00001011 | 28 | 0x1C | 00011100 |
| 12 | 0x0C | 00001100 | 29 | 0x1D | 00011101 |
| 13 | 0x0D | 00001101 | 30 | 0x1E | 00011110 |
| 14 | 0x0E | 00001110 | 31 | 0x1F | 00011111 |
| 15 | 0x0F | 00001111 | 32 | 0x20 | 00100000 |
| 16 | 0x10 | 00010000 |
Look at the hex column: it counts 0-9, then A-F, then rolls over to 0x10 – exactly like decimal rolls from 9 to 10. The binary column shows why hex is so convenient: the upper nibble (first 4 bits) changes only when the first hex digit changes, and the lower nibble tracks the second hex digit. Once you see this alignment, reading hex dumps starts to feel natural.
Hex in Programming
Most languages have hex literals:
| Language | Hex literal | Example |
|---|---|---|
| C / C++ / Java / JavaScript | `0x` prefix | `0xFF` |
| Python | `0x` prefix | `0xFF` |
| CSS | `#` prefix | `#FF5733` |
| Assembly | `h` suffix or `$` | `FFh`, `$FF` |
Bitwise operations (AND, OR, XOR, shifts) are far easier to reason about in hex than decimal, because each digit maps to a clean 4-bit nibble.
Frequently Asked Questions
Is hexadecimal the same as “hex”?
Yes – “hex” is just the short form. Both refer to the base-16 number system.
Why not use base-32 or base-64 instead?
Base-64 exists (it’s used in data encoding), but hex wins for readability because each digit is exactly half a byte – a natural unit. Base-32 digits don’t align with byte boundaries.
What’s the largest value one hex digit can hold?
F = 15. Two digits (one byte) max out at 0xFF = 255.
How do you pronounce hexadecimal?
“hex-uh-DESS-ih-mul.” Programmers usually just say “hex.”
Where can I practice hex conversions?
Our binary converter now includes dedicated hex modes – hex to text, text to hex, and two-way hex↔binary – so you can check your work instantly.