Binary numbers
Hexadecimal
Goal: Convert between hexadecimal, binary and decimal · 9 min
Long bit strings are hard to read, so programmers use base 16 (hexadecimal). Digits: 0–9, then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Place values: 1, 16, 256, …
The trick: one hex digit = exactly 4 bits (a nibble). 1101 0110₂ → 1101 = D, 0110 = 6 → D6₁₆ = 13·16 + 6 = 214.
You meet hex everywhere: colours in CSS (#FF8800 = red 255, green 136, blue 0), memory addresses, Unicode code points (U+00E4 = ä). Prefixes: 0x in code (0xD6), # in CSS.
Worked example: Colour #3CB371
- Red 3C = 3·16 + 12 = 60.
- Green B3 = 11·16 + 3 = 179.
- Blue 71 = 7·16 + 1 = 113 → rgb(60, 179, 113).