Why Different Number Bases Exist
- Binary (2): Computers use it—transistors are either ON (1) or OFF (0)
- Octal (8): Unix file permissions (chmod 755), compact binary representation
- Decimal (10): Humans have 10 fingers—that's literally why we use base 10
- Hex (16): 4 bits = 1 hex digit, perfect for representing bytes compactly
Hex Colors Decoded
- #FF0000: Red=255, Green=0, Blue=0 → Pure red
- #00FF00: Red=0, Green=255, Blue=0 → Pure green
- #0000FF: Red=0, Green=0, Blue=255 → Pure blue
- #FFFFFF: All channels maxed (255,255,255) → White
- #000000: All channels zero → Black
- Why hex?: FF = 255 in decimal, fits in 2 chars instead of 3
Binary Tricks Programmers Use
- Powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024...
- Check if power of 2: n & (n-1) === 0 (bit manipulation magic)
- Multiply by 2: Shift left: 5 << 1 = 10 (0101 → 1010)
- Divide by 2: Shift right: 10 >> 1 = 5 (1010 → 0101)
- Odd/even check: n & 1 — if 1, it's odd (last bit is 1)
Unix Permissions Explained
- chmod 755: 7=rwx (owner), 5=r-x (group), 5=r-x (others)
- 7 in binary: 111 = read(4) + write(2) + execute(1)
- 5 in binary: 101 = read(4) + execute(1), no write
- chmod 644: rw-r--r-- (owner can write, others read only)
- Why octal?: 3 permission bits map perfectly to 1 octal digit
Memory & Addresses
- Hex addresses: 0x7FFF5FBFF8AC is easier to read than 140734799804588
- Byte values: 0x00-0xFF = 0-255 decimal = 8 bits = 1 byte
- Word size: 32-bit = 0xFFFFFFFF max, 64-bit = 0xFFFFFFFFFFFFFFFF
- NULL pointer: 0x0000000000000000 (all zeros)
- Debug patterns: 0xDEADBEEF, 0xCAFEBABE, 0xBAADF00D mark uninitialized memory
Base36 & URL Shorteners
- Base36 uses 0-9 and A-Z (case insensitive)
- YouTube IDs: 11 chars in base64-like encoding = billions of unique videos
- bit.ly/xyz: Short codes are base62 (0-9, a-z, A-Z)
- Why not base64?: Confusion between l/1, O/0, and + / in URLs
- Reddit post IDs: Base36 encoding of incrementing numbers
Fun Number Facts
- 0xDEADBEEF: Classic hex 'magic number' = 3735928559 in decimal
- 0xCAFEBABE: Java class file magic number (appears at start of .class files)
- 255: Max value of a byte (0xFF), why RGB colors go 0-255
- 65535: Max value of 16-bit unsigned int (0xFFFF)
- 2147483647: Max 32-bit signed int (0x7FFFFFFF), often seen in games as max gold
- Babylonians used base 60: That's why we have 60 seconds and 360 degrees!
Quick Reference
- 0b1010: Binary literal in JS/Python/Rust = 10 decimal
- 0o755: Octal literal in JS/Python = 493 decimal
- 0xFF: Hex literal in most languages = 255 decimal
- parseInt('FF', 16): JS: parse hex string → 255
- (255).toString(16): JS: decimal to hex string → 'ff'