The Plain Picture#
Binary is great for machines and terrible for humans. Try reading this out loud:
1100 1000 1111 1111 0000 1010. You'll lose your place.
Humans need a shorter way to write the same bits — like writing "12" instead of "twelve".
The Real Name#
Hexadecimal (or hex, or base 16) uses 16 digits:
0 1 2 3 4 5 6 7 8 9 A B C D E F
10 11 12 13 14 15 ← decimal values of A–FHex numbers are usually written with a 0x in front so you know they're hex: 0xFF.
In web colours they're written with # instead: #FF8800.
Under the Hood#
The magic fact: 16 = 2⁴, so one hex digit is exactly 4 bits. Group bits in fours and swap each group for one hex digit:
binary: 1100 1000 (our score, 200)
groups: 1100 | 1000
values: 12 | 8
hex: C | 8 → 0xC8Check: C = 12, so 12 × 16 + 8 = 192 + 8 = 200 ✔
So one byte is always exactly two hex digits: 0x00 (0) up to 0xFF (255). That is why hex is
used everywhere a computer shows raw bytes.
Colours — the orange score. A screen colour is usually 3 bytes: how much Red, Green and Blue light to mix, each from 0 to 255.
#FF8800 → FF 88 00
R G B
255 136 0 → full red + half green + no blue = orangeGotchas
0x10is 16, not ten. Always check which base a number is in.Hex is only a way of writing bits for humans. The computer stores exactly the same bits either way.
Check yourself
3 questionsWhy is one byte always exactly two hex digits?
Show answerHide answer
One hex digit is 4 bits (16 = 2⁴); a byte is 8 bits, which is two groups of 4.
Convert 0x2F to decimal.
Show answerHide answer
2 × 16 + 15 = 47.
What colour is #00FF00?
Show answerHide answer
Pure green (red 0, green 255, blue 0).