- Binary (base 2) — digits 0, 1 — used inside the computer.
- Octal (base 8) — digits 0–7.
- Decimal (base 10) — digits 0–9 — used by humans in daily life.
- Hexadecimal (base 16) — digits 0–9 and A–F — used to write memory addresses & colour codes.
5.1 Why do Computers Use Binary?
A computer is built from billions of tiny electronic switches called transistors. A transistor has only two states — either it is conducting current (ON) or it is not (OFF). We represent these two states with the two digits 1 and 0. Any information the computer handles — numbers, letters, sounds, images — must first be expressed using just these two digits. That is why binary is the native language of every computer.
5.2 Positional Value & Base
In any number system, each digit's value depends on its position. The rightmost digit is multiplied by base0, the next by base1, and so on. So in decimal, the number 375 actually means:
The same rule applies to every other base — we just replace 10 with the appropriate base. This is called the positional weight of a digit.
5.3 The Four Number Systems at a Glance
| System | Base | Digits Used | Example | Where you see it |
|---|---|---|---|---|
| Binary | 2 | 0, 1 | 10112 | Inside all digital circuits, RAM, network signals. |
| Octal | 8 | 0, 1, 2, 3, 4, 5, 6, 7 | 178 | Unix/Linux file permissions (chmod 755). |
| Decimal | 10 | 0 – 9 | 19710 | Everyday human counting. |
| Hexadecimal | 16 | 0 – 9, A, B, C, D, E, F | 1A16 | Memory addresses, HTML colour codes (#FF5733), MAC addresses. |
5.4 Equivalent Values — Counting 0 to 15
The easiest way to get a feel for all four systems is to count side-by-side from 0 to 15:
| Decimal | Binary (4-bit) | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
5.5 Converting from Decimal to Another Base
Rule: divide the decimal number repeatedly by the target base. Write down the remainders each time. When the quotient becomes 0, stop. The answer is the remainders read bottom to top.
5.5.1 Decimal → Binary (÷ 2)
25 ÷ 2 = 12 remainder 1 ← LSB (least significant bit) 12 ÷ 2 = 6 remainder 0 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 ← MSB (most significant bit) Read remainders bottom-to-top: 11001 ∴ 25₁₀ = 11001₂Verify: 1·16 + 1·8 + 0·4 + 0·2 + 1·1 = 25. ✓
5.5.2 Decimal → Octal (÷ 8)
157 ÷ 8 = 19 remainder 5 19 ÷ 8 = 2 remainder 3 2 ÷ 8 = 0 remainder 2 Read bottom-to-top: 235 ∴ 157₁₀ = 235₈Verify: 2·64 + 3·8 + 5·1 = 128 + 24 + 5 = 157. ✓
5.5.3 Decimal → Hexadecimal (÷ 16)
254 ÷ 16 = 15 remainder 14 → E 15 ÷ 16 = 0 remainder 15 → F Read bottom-to-top: FE ∴ 254₁₀ = FE₁₆Verify: 15·16 + 14·1 = 240 + 14 = 254. ✓ Remember: in hex, 10–15 map to A, B, C, D, E, F.
5.6 Converting to Decimal from Another Base
Rule: multiply each digit by its positional weight (baseposition) and add the results.
5.6.1 Binary → Decimal
Position: 4 3 2 1 0
Digit: 1 0 1 1 0
Weight: 16 8 4 2 1
Value = 1·16 + 0·8 + 1·4 + 1·2 + 0·1
= 16 + 0 + 4 + 2 + 0
= 22
∴ 10110₂ = 22₁₀
5.6.2 Octal → Decimal
Value = 3·8² + 4·8¹ + 7·8⁰
= 3·64 + 4·8 + 7·1
= 192 + 32 + 7
= 231
∴ 347₈ = 231₁₀
5.6.3 Hexadecimal → Decimal
Digits in decimal: 2, A=10, F=15
Value = 2·16² + 10·16¹ + 15·16⁰
= 2·256 + 10·16 + 15·1
= 512 + 160 + 15
= 687
∴ 2AF₁₆ = 687₁₀
5.7 Binary ⇄ Octal (group of 3 bits)
Because 23 = 8, every 3 binary digits correspond to exactly one octal digit. So conversion between the two is just a matter of grouping.
5.7.1 Binary → Octal
Starting from the right, split the binary number into groups of 3. Pad the leftmost group with leading zeros if required. Replace each group with its octal equivalent.
1101011 Group from right, padding left with 0: 001 101 011 1 5 3 ∴ 1101011₂ = 153₈
5.7.2 Octal → Binary
Replace each octal digit with its 3-bit binary equivalent.
Octal: 2 4 7 Binary: 010 100 111 ∴ 247₈ = 010100111₂ (leading zero optional: 10100111₂)
5.8 Binary ⇄ Hexadecimal (group of 4 bits)
Because 24 = 16, every 4 binary digits correspond to exactly one hexadecimal digit. Same idea, different group size.
5.8.1 Binary → Hexadecimal
110110101 Group from right, padding left with 0: 0001 1011 0101 1 B 5 ∴ 110110101₂ = 1B5₁₆
5.8.2 Hexadecimal → Binary
Hex: 3 A F Binary: 0011 1010 1111 ∴ 3AF₁₆ = 001110101111₂
5.9 Octal ⇄ Hexadecimal (via Binary)
There is no direct short-cut between octal and hex — the two groupings don't line up. The usual route is through binary: convert octal → binary → hex (or hex → binary → octal).
Step 1 — Octal → Binary (each digit to 3 bits): 3 7 5 011 111 101 → 011111101₂ Step 2 — Regroup into 4-bit chunks (from right) for hex: 0000 1111 1101 (pad leading zeros) 0 F D ∴ 375₈ = FD₁₆
5.10 Conversion Map — Summary Diagram
| From ↓ \ To → | Decimal (10) | Binary (2) | Octal (8) | Hexadecimal (16) |
|---|---|---|---|---|
| Decimal | — | Repeatedly ÷ 2; read remainders bottom-up | Repeatedly ÷ 8; read remainders bottom-up | Repeatedly ÷ 16; read remainders bottom-up (10–15 = A–F) |
| Binary | Σ bᵢ · 2ⁱ (sum of each bit × 2position) |
— | Group bits in 3s from the right; each group = 1 octal digit | Group bits in 4s from the right; each group = 1 hex digit |
| Octal | Σ dᵢ · 8ⁱ | Replace each octal digit with its 3-bit binary form | — | Via binary → Oct → Bin → Hex |
| Hexadecimal | Σ dᵢ · 16ⁱ | Replace each hex digit with its 4-bit binary form | Via binary → Hex → Bin → Oct | — |
dn-1 … d2 d1 d0 (rightmost digit is position 0) in base b, then its decimal value is
Value = dn-1·bn-1 + … + d2·b2 + d1·b1 + d0·b0
Example (hex):
2AF16 → 2·162 + 10·161 + 15·160 = 512 + 160 + 15 = 687.
📌 Quick Revision — Chapter 5 at a Glance
- Computers use binary because every transistor is either ON (1) or OFF (0).
- Base/Radix = number of distinct digits — Binary 2, Octal 8, Decimal 10, Hex 16.
- Positional value: value = digit × baseposition.
- Hex digits A–F = decimal 10–15.
- Decimal → base N: divide by N, read remainders bottom-to-top.
- Base N → Decimal: Σ dᵢ · Nⁱ.
- Binary ↔ Octal: group of 3 bits = 1 octal digit.
- Binary ↔ Hex: group of 4 bits = 1 hex digit.
- Octal ↔ Hex: no direct — always via binary.