AiTechWorlds
AiTechWorlds
Imagine a room with one billion light switches. Each one is either ON or OFF. Nothing in between — no dimmer, no partial state, just two positions.
That's your computer's memory.
Every piece of data — this sentence, a YouTube video, a bank transaction, a 3D game world — exists inside your machine as a colossal arrangement of switches, each either ON (1) or OFF (0). The reason is physics: transistors are the world's best switches, and switches have two stable states. Building a reliable three-state transistor at nanometer scale is extraordinarily difficult. Binary is not a human preference. It's the language of electrons in silicon.
A modern CPU transistor operates at either ~0V (logic 0) or ~1.0–3.3V (logic 1), depending on the process node. There is a forbidden zone in between — any voltage there represents an error.
This design gives us noise immunity: even if a wire picks up interference and the voltage wavers from 1.0V to 1.15V, the transistor still reliably reads it as "1". With three or more states, those margins shrink dramatically and errors multiply.
The result: Every circuit in your CPU, RAM, SSD, and GPU operates in binary. Choosing base-2 is not arbitrary — it is thermodynamically optimal for silicon-based electronics.
In the decimal system (base-10), each digit position represents a power of 10:
365 = 3×10² + 6×10¹ + 5×10⁰
In binary (base-2), each digit represents a power of 2:
1011 = 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11
Each binary digit is called a bit (binary digit). Eight bits form a byte.
To convert 42 to binary, repeatedly divide by 2 and record remainders:
42 ÷ 2 = 21 remainder 0 ← least significant bit
21 ÷ 2 = 10 remainder 1
10 ÷ 2 = 5 remainder 0
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 ← most significant bit
Read remainders bottom-up: 101010
42 in decimal = 101010 in binary ✓
101010 = 1×32 + 0×16 + 1×8 + 0×4 + 1×2 + 0×1
= 32 + 8 + 2
= 42 ✓
Octal uses digits 0–7, where each position represents a power of 8. It was widely used in early computing because 3 binary digits map perfectly to 1 octal digit.
Primary use today: Unix/Linux file permissions.
When you type chmod 755 in a terminal, those three digits are octal:
Octal 377 = 3×64 + 7×8 + 7×1 = 192 + 56 + 7 = 255 (decimal)
Binary: 011 111 111 = 11111111
Hexadecimal (hex) uses 16 symbols: 0–9 then A–F (where A=10, B=11, C=12, D=13, E=14, F=15).
The power of hex: 4 binary digits = 1 hex digit exactly. This makes hex a compact, human-readable representation of raw binary data.
Converting 255 to hex:
255 ÷ 16 = 15 remainder 15 → F
15 ÷ 16 = 0 remainder 15 → F
Read bottom-up: FF
255 = 0xFF = 0b11111111 = 0o377
0x7fff5b8a0000 (stack address on x86-64 macOS)#FF5733 = Red 255, Green 87, Blue 510x90 is the NOP (no operation) instruction on x86| System | Notation | Value |
|---|---|---|
| Decimal | 255 | 2×100 + 5×10 + 5×1 |
| Binary | 0b11111111 | 8 bits, all 1s |
| Octal | 0o377 | 3×64 + 7×8 + 7×1 |
| Hexadecimal | 0xFF | 15×16 + 15×1 |
This number is significant: 255 is the maximum value of an 8-bit unsigned integer — the largest number a single byte can store.
How does a computer store -5? It can't use a minus sign — those don't exist in binary.
Sign-magnitude (naive approach): use the leftmost bit as a sign. Problem: you get +0 and -0, and addition hardware needs special cases.
Two's complement (the universal standard): To negate a number, flip all bits, then add 1.
Start with +5: 00000101
Flip all bits: 11111010
Add 1: 11111011 ← this is -5 in two's complement
Verify: +5 + (-5) should equal 0.
00000101 (+5)
+ 11111011 (-5)
──────────
100000000 → the 9th bit overflows and is discarded → 00000000 ✓
The genius of two's complement: subtraction is just addition with a negated operand. The CPU needs only an adder, not a separate subtractor.
An 8-bit unsigned integer can hold values 0–255. What happens when you add 200 + 100?
200 = 11001000
100 = 01100100
Sum = 100101100 ← 9 bits! The carry bit is lost.
00101100 = 44 (decimal)
200 + 100 = 44 in an 8-bit system. This is integer overflow — a real bug source. The classic example: the Ariane 5 rocket explosion in 1996 was caused by a 64-bit float converted to a 16-bit integer overflowing, triggering a self-destruct command.
| System | Base | Digits Used | Example (42) | Prefix | Used In |
|---|---|---|---|---|---|
| Binary | 2 | 0, 1 | 101010 | 0b | Hardware, low-level programming |
| Octal | 8 | 0–7 | 52 | 0o / 0 | Unix file permissions |
| Decimal | 10 | 0–9 | 42 | none | Human math, high-level code |
| Hexadecimal | 16 | 0–9, A–F | 2A | 0x | Memory addresses, colors, opcodes |
chmod 755)Get this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises