Number Systems & Binary Arithmetic
The Four Number Systems
Why This Matters — Every digital circuit - from a simple AND gate to a billion-transistor processor - processes information as 0s and 1s. Before understanding gates, flip-flops, or RTL, you must be fluent in the four number systems engineers use daily: Binary, Octal, Decimal, and Hexadecimal.
The Four Number Systems
| System | Base | Digits Used | Where Used |
|---|---|---|---|
| Binary | 2 | 0, 1 | Inside every digital circuit - the language of logic |
| Octal | 8 | 0–7 | Compact notation for binary groups; Unix permissions |
| Decimal | 10 | 0–9 | Human-readable; used in specifications |
| Hexadecimal | 16 | 0–9, A–F | Memory addresses, register values, color codes |
Place Value - The Core Concept
Every number system works by assigning a positional weight to each digit. The rightmost digit has weight base0 = 1, the next has base1, then base2, and so on.
Value = dn×Bn + dn-1×Bn-1 + … + d1×B1 + d0×B0Worked Example - Binary to Decimal — Convert 10112 to decimal: 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 1110
Conversion Techniques
Decimal → Binary (Repeated Division by 2)
Divide the number by 2 repeatedly. The remainders read bottom to top give the binary result.
Example: 13 → Binary 13 ÷ 2 = 6 remainder 1 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 Read up → 11012
Binary → Hexadecimal (Group by 4)
Group binary digits into sets of 4 from the right. Each group maps to one hex digit.
Example: 101101112 1011 | 0111 B | 7 Result: B716
Hex → Binary is the reverse: expand each hex digit into 4 bits.
Quick Reference: 0–15 in All Bases
| 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 |
Signed Binary - 2's Complement (Most Important)
Real hardware must represent negative numbers. The standard method in all modern CPUs and digital circuits is 2's complement.
Sign-Magnitude
MSB = sign bit (0=+, 1=−). Remaining bits = magnitude. Problem: has two representations of zero (+0 and −0). Rarely used in hardware.
1's Complement
Invert all bits. Still has two zeros. Addition requires an end-around carry. Mostly historical.
2's Complement
Invert all bits, then add 1. One unique zero. Subtraction becomes addition. Used in all modern computers and VLSI designs.
How to Find 2's Complement of a Number — Step 1: Write the binary representation. Step 2: Invert every bit (1→0, 0→1). This is the 1's complement. Step 3: Add 1 to the result. Example: −5 in 4-bit 2's complement +5 = 0101 → Invert → 1010 → Add 1 → 1011 Range for N-bit 2's complement: −2N-1 to +2N-1−1 For 8 bits: −128 to +127
For N bits: Minimum = −2N−1 | Maximum = 2N−1 − 1Binary Arithmetic
Binary Addition Rules
0 + 0 = 0, carry 0 0 + 1 = 1, carry 0 1 + 0 = 1, carry 0 1 + 1 = 0, carry 1 1 + 1 + 1 = 1, carry 1
Example: 0101 + 0011 0101 (5) + 0011 (3) ────── 1000 (8)
Subtraction via 2's Complement
A − B = A + (2's complement of B)
Example: 7 − 3 (4-bit) 7 = 0111 3 = 0011 → 2's comp = 1101 0111 + 1101 = 10100 Drop the carry → 0100 = 4
This is exactly how ALUs in CPUs work.
BCD - Binary Coded Decimal
BCD represents each decimal digit independently in 4 bits. Used in calculators, digital clocks, and displays where you need to show decimal digits directly.
BCD Key Rules — Each decimal digit (0–9) maps to its 4-bit binary equivalent. Codes 1010–1111 (10–15) are invalid in BCD. Example: 3910 in BCD = 0011 1001 (NOT the same as 39 in pure binary which is 00100111). BCD arithmetic: if sum of two BCD digits > 9, add 0110 (6) to correct it and generate a carry.