Core answer: Programmers convert between binary/decimal/hex daily: hex is binary in 4-bit groups (0xF = 1111 = 15), one byte = 2 hex digits = 8 bits = 0–255. Signed integers use two's complement: int8 spans −128 to 127, uint8 spans 0–255. Memorize the powers of 2 up to 2¹⁶ = 65,536 — they are the vocabulary of computing.
The essential tables
| Hex | Binary | Dec | Hex | Binary | Dec |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | A | 1010 | 10 |
| 3 | 0011 | 3 | B | 1011 | 11 |
| 4 | 0100 | 4 | C | 1100 | 12 |
| 5 | 0101 | 5 | D | 1101 | 13 |
| 6 | 0110 | 6 | E | 1110 | 14 |
| 7 | 0111 | 7 | F | 1111 | 15 |
Powers of 2 worth memorizing
2⁸=256 · 2¹⁰=1,024 (K) · 2¹⁶=65,536 · 2²⁰=1,048,576 (M) · 2³⁰≈10.7亿 (G) · 2³²≈42.9亿 · 2⁶⁴≈1.8×10¹⁹
Two's complement in one minute
Negative numbers store as "invert all bits, add 1": −1 in int8 = 1111 1111; −128 = 1000 0000. Benefits: one zero, addition just works, and overflow wraps silently — (int8)127 + 1 = −128. That wraparound is the root of countless bugs (and the Gandhi-nuclear bug in Civilization lore).
Worked examples
Example 1 — Reading a memory dump. Bytes "48 65 6C 6C 6F" in hex = ASCII "Hello". Two hex digits per byte makes hex the universal byte notation.
Example 2 — Bitmasking permissions. Flags READ=0b001, WRITE=0b010, EXEC=0b100: rw = 0b110 = 6. Test a bit: (flags & WRITE) != 0; set it: flags |= WRITE; clear: flags &= ~WRITE.
Example 3 — Color math. #FF8000: red=0xFF=255, green=0x80=128, blue=0. Halving brightness: >>1 per channel conceptually (with rounding care).
Example 4 — Why 0.1 + 0.2 ≠ 0.3. Binary floating point can't represent 0.1 finitely (like 1/3 in decimal): the sum is 0.30000000000000004. Money must use integer cents or decimal types — never float.
Common mistakes and myths
- Off-by-one in ranges — uint8 holds 0–255 = 256 values, not 0–256; array of 10 has indices 0–9.
- Signed overflow assumptions — in C it's undefined behavior (not guaranteed wraparound); in Java it wraps; check your language.
- Confusing KB with KiB — see the data storage guide; 2⁴⁰ ≠ 10¹².
- Char = byte — in UTF-8 a Chinese char is 3 bytes, an emoji 4; byte counts ≠ character counts.
- Assuming floats are exact — use integer minor units for currency and epsilon comparisons for floats.