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 digit = 4 bits (nibble)
HexBinaryDecHexBinaryDec
000000810008
100011910019
200102A101010
300113B101111
401004C110012
501015D110113
601106E111014
701117F111115

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

  1. Off-by-one in ranges — uint8 holds 0–255 = 256 values, not 0–256; array of 10 has indices 0–9.
  2. Signed overflow assumptions — in C it's undefined behavior (not guaranteed wraparound); in Java it wraps; check your language.
  3. Confusing KB with KiB — see the data storage guide; 2⁴⁰ ≠ 10¹².
  4. Char = byte — in UTF-8 a Chinese char is 3 bytes, an emoji 4; byte counts ≠ character counts.
  5. Assuming floats are exact — use integer minor units for currency and epsilon comparisons for floats.