Base 16 — ten digits plus A through F, and four bits per character. A plain-English guide to number systems from TorchAnvil.
Hex is base 16. It reuses the familiar digits 0 through 9 and
then borrows the letters A through F to stand in for the values 10
through 15. That gives you sixteen single-character digits — exactly
enough to cover every pattern of four bits.
Binary is honest about what the hardware is doing, but it's painful
for humans. A 32-bit address written out in full is thirty-two
characters of 0 and 1, and your eyes slide right off it. Miss a
bit in the middle and you won't notice until something explodes.
Hex fixes this by packing four bits into a single character. A 32-bit number becomes eight hex digits. You can read it, you can compare two of them by eye, you can copy one onto a sticky note without losing your place. The information is identical — it's just denser, and denser is easier when you're the one reading it.
Every hex digit corresponds to a four-bit group (a nibble). Here is the full 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 |
A is not a special letter — it's just the name for "ten" as a single
digit. The same way 9 is the name for nine.
Take 2F. Each column is a power of sixteen, starting from 1 on
the right:
| Digit | 2 | F |
|---|---|---|
| Column value | 16 | 1 |
So 2F is 2 × 16 + 15 × 1 = 32 + 15 = 47 in decimal.
Here's the other angle, the one that makes hex click: every hex digit
is exactly four bits. 2 is 0010 and F is 1111, so 2F in
binary is 0010 1111. You can convert between hex and binary one
digit at a time — no math, just look-up. That property is the whole
reason programmers reach for hex instead of decimal when they're
working close to the hardware.
Once you notice hex, you'll see it everywhere:
0x, as
in 0x7FFE or 0x0040.#1E3A5F — two hex digits each for
red, green, and blue.U+2603 for the snowman character.0 through F.Four-bit circuits like the adder in the library are effectively
processing a single hex digit per tick. When you watch their outputs
flicker from 0000 through 1111, you're watching a hex digit count
from 0 to F.
Open the Base Converter, type a decimal number,
and watch the hex and binary columns update together. Step from 9 to
10 to see the jump from 9 to A, and step from 15 to 16 to see
F roll over into 10 — one hex digit up, the next one along.