codeworking.org
Search
Course Syllabus (Lesson 03 of 03)
Computer Science Fundamentals • Module 02 15 min read

Boolean Logic & Logic Gates

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:

  1. CONJUNCTION (AND)
  2. DISJUNCTION (OR)
  3. 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 Bit A (0 / 1)
Inverter Gate NOT (¬A)
Output Bit Q (Flipped)
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.

Inputs A & B (Two Wires)
Conjunction Gate AND (A ∧ B)
Output Q = 1 (Only if Both = 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.

Inputs A & B (Two Wires)
Disjunction Gate OR (A ∨ B)
Output Q = 1 (If Any = 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.

Inputs A & B (Two Wires)
Exclusive Gate XOR (A ⊕ B)
Output Q = 1 (Only if Distinct)
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 binary 10₂), so the single-digit sum is 0 with a carry of 1!


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 = 210₂ (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:

Half-Adder Circuit Inputs: [ Bit A ] + [ Bit B ]
Dual-Gate Binary Arithmetic Engine
⬇ Split into Parallel Logic Gates ⬇
XOR Gate Engine Sum Bit (S = A ⊕ B) Computes the single-digit binary addition value
AND Gate Engine Carry Bit (C = A ∧ B) Detects overflow (1 + 1 = 10₂) to carry to the next column

By connecting multiple adders together, engineers build 64-bit ALUs (Arithmetic Logic Units) capable of performing billions of mathematical calculations every second!


Summary Table

GateBoolean LogicOutput Rule
NOT¬AInverts input (1 → 0, 0 → 1)
ANDA ∧ BTrue only when all inputs are True
ORA ∨ BTrue when any input is True
XORA ⊕ BTrue 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!

S

Computer Science educator, Software Engineer, Cloud Computing & Cloud Native Architect, and AI/ML Engineer. Founder & Owner of unus.one, softwork.ing, and codeworking.org.

Comments & Discussion