In the previous lesson, we saw how transistors act as electrical switches with states 0 (Off) and 1 (On).
A single switch alone cannot think or calculate. But when you wire two or three transistors together in specific circuit patterns, they perform logic operations. These circuits are called Logic Gates.
In this lesson, we will learn how basic logic gates make decisions and perform binary arithmetic inside the Central Processing Unit (CPU).
1. George Boole & Boolean Algebra
In 1854, English mathematician George Boole created a system of mathematical logic where variables can only have two truth values: TRUE (1) or FALSE (0).
In Boolean algebra, there are three fundamental primary operations:
- CONJUNCTION (AND)
- DISJUNCTION (OR)
- NEGATION (NOT)
Nearly a century later, in 1937, MIT engineer Claude Shannon proved that Boolean algebra could be physically built using electric switches, launching the digital electronic revolution.
2. The Fundamental Logic Gates
A. The NOT Gate (Inverter)
The NOT gate takes a single input and flips it. If input is 1, output is 0. If input is 0, output is 1.
| Input A | Output Q |
|---|---|
| 0 | 1 |
| 1 | 0 |
B. The AND Gate
The AND gate has two inputs. The output is 1only if both Input A AND Input B are 1.
| Input A | Input B | Output Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Real-world analogy: You can start the car only if the key is turned (1) AND the brake pedal is pressed (1).
C. The OR Gate
The OR gate outputs 1if at least one of the inputs (A or B) is 1.
| Input A | Input B | Output Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Real-world analogy: A security alarm rings if the front door opens (1) OR a window breaks (1).
D. The XOR Gate (Exclusive OR)
The XOR gate outputs 1if exactly one input is 1, but NOT both.
| Input A | Input B | Output Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
[!TIP] XOR is the foundation of addition in computers. Notice that
1 + 1 = 2(in binary10₂), so the single-digit sum is0with a carry of1!
3. How Gates Do Real Math: The Half-Adder Circuit
How does a CPU add two single-bit numbers (A + B)?
Let’s look at binary addition rules:
0 + 0 = 0(Sum:0, Carry:0)0 + 1 = 1(Sum:1, Carry:0)1 + 0 = 1(Sum:1, Carry:0)1 + 1 = 2→10₂(Sum:0, Carry:1)
Notice the pattern:
- The Sum column matches the XOR gate!
- The Carry column matches the AND gate!
By wiring one XOR gate and one AND gate together, we create a Half-Adder:
By connecting multiple adders together, engineers build 64-bit ALUs (Arithmetic Logic Units) capable of performing billions of mathematical calculations every second!
Summary Table
| Gate | Boolean Logic | Output Rule |
|---|---|---|
| NOT | ¬A | Inverts input (1 → 0, 0 → 1) |
| AND | A ∧ B | True only when all inputs are True |
| OR | A ∨ B | True when any input is True |
| XOR | A ⊕ B | True when inputs are different |
| NAND | ¬(A ∧ B) | Inverted AND (Universal Gate) |
| NOR | ¬(A ∨ B) | Inverted OR (Universal Gate) |
Congratulations!
You now understand the bridge between electricity, logic gates, and computational arithmetic. You have mastered the core hardware foundations of computer science!