Why Multiple Number Systems?
Humans count in base 10 (decimal) because we have ten fingers. Computers are built from transistors that can be either on or off — a natural fit for base 2 (binary). Programmers use hexadecimal (base 16) as a compact shorthand for binary. Octal (base 8) appears in file permissions and older computing contexts.
Understanding these systems demystifies a lot of technical documentation, programming concepts, and low-level computing.
Decimal: Base 10 (What You Already Know)
In decimal, each digit position represents a power of 10. The number 3,742 means: - 3 × 10³ = 3,000 - 7 × 10² = 700 - 4 × 10¹ = 40 - 2 × 10⁰ = 2 - Total: 3,742
This positional value principle applies to every number system — only the base changes.
Binary: Base 2
Binary uses only two digits: 0 and 1. Each position represents a power of 2.
The binary number 1011 means: - 1 × 2³ = 8 - 0 × 2² = 0 - 1 × 2¹ = 2 - 1 × 2⁰ = 1 - Total: 11 in decimal
**Converting decimal to binary:** Repeatedly divide by 2 and record the remainders. To convert 25: - 25 ÷ 2 = 12 remainder **1** - 12 ÷ 2 = 6 remainder **0** - 6 ÷ 2 = 3 remainder **0** - 3 ÷ 2 = 1 remainder **1** - 1 ÷ 2 = 0 remainder **1** Reading remainders bottom to top: **11001** (which is 16 + 8 + 1 = 25 ✓)
Computers store everything — text, images, audio, code — as binary. A single bit is 0 or 1. Eight bits form a byte, which can represent 256 values (0–255). Text is stored as binary codes (ASCII, Unicode). Images are stored as binary values for each pixel's color channels.
Hexadecimal: Base 16
Hexadecimal uses 16 digits: 0–9 and A–F (where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15). Hex is popular among programmers because every hex digit corresponds to exactly 4 binary bits, making conversion between hex and binary effortless.
The hex number `2F` means: - 2 × 16¹ = 32 - F (15) × 16⁰ = 15 - Total: 47 in decimal
**Why programmers love hex:** A byte (8 bits) can be represented as exactly two hex digits. The byte 11001111 in binary = CF in hex. It is much more compact to write `0xFF` than `11111111`, and far less prone to transcription errors.
You encounter hex constantly in computing: - **Colors in CSS:** `#FF5733` means FF (255) red, 57 (87) green, 33 (51) blue - **Memory addresses:** `0x00401234` in debuggers and assembly - **MAC addresses:** `00:1A:2B:3C:4D:5E` — six pairs of hex digits - **SHA-256 hashes:** 64 hex characters representing a 256-bit value - **Unicode code points:** U+1F600 is the emoji 😀
The prefix `0x` in programming denotes a hexadecimal literal. `0b` denotes binary, `0o` denotes octal.
Octal: Base 8
Octal uses digits 0–7. It appears primarily in Unix/Linux file permissions.
When you run `chmod 755` in a terminal, each digit is an octal number representing a set of permissions: - 7 = 111 in binary = read (4) + write (2) + execute (1) - 5 = 101 in binary = read (4) + execute (1)
So `755` means: owner has full permissions (rwx), group and others have read and execute but not write (r-x).
Converting Between Bases
**Binary to hex:** Group binary digits into sets of 4 from the right, then convert each group to a hex digit. 11011010 → 1101 | 1010 → D | A → `0xDA` (= 218 decimal)
**Hex to binary:** Replace each hex digit with its 4-bit binary equivalent. `0xB7` → 1011 | 0111 → 10110111
**Any base to decimal:** Multiply each digit by its positional value (base^position) and sum.
**Decimal to any base:** Repeatedly divide by the target base, record remainders, read bottom to top.
Bitwise Operations
Bitwise operations work directly on the binary representation of integers. They are fundamental to low-level programming, cryptography, and network protocols.
- **AND (&):** Each output bit is 1 only if both input bits are 1. Used for masking bits.
- **OR (|):** Each output bit is 1 if either input bit is 1. Used for setting bits.
- **XOR (^):** Each output bit is 1 if the input bits are different. Used in encryption.
- **NOT (~):** Flips every bit. ~5 = -6 in two's complement arithmetic.
- **Left shift (<<):** Shifts bits left, multiplying by 2 per position. 5 << 1 = 10.
- **Right shift (>>):** Shifts bits right, dividing by 2 per position. 8 >> 1 = 4.
Understanding these operations is essential for writing efficient low-level code, implementing network subnet calculations, and understanding how encryption algorithms work at the bit level.