Introduction to Logic Gates and Boolean Logic

Welcome! In this chapter, we are going to explore the "brain cells" of a computer. While humans use words and feelings to process information, computers use electricity. Specifically, they use tiny switches called transistors to decide whether electricity should flow (represented as \(1\)) or not (represented as \(0\)).

Logic gates are the building blocks of all digital systems. By the end of these notes, you will understand how computers use these gates to make decisions, from simple arithmetic to running complex software. Don't worry if it seems abstract at first—we'll use plenty of real-world analogies to make it click!

Note: This topic is closely linked to "Data representation and number systems," where we learn how these \(1\)s and \(0\)s represent numbers and text.

What is Boolean Logic?

Boolean logic is a form of algebra where all values are reduced to either TRUE or FALSE. In computer science, we represent these as:

  • TRUE = \(1\) (Electricity is ON)
  • FALSE = \(0\) (Electricity is OFF)

A logic gate is a physical device (built into a microchip) that takes one or more inputs and produces a single output based on a specific rule.

1. The Three Fundamental Gates

Almost every complex circuit in your phone or laptop is built using combinations of these three basic gates.

The NOT Gate (The "Opposite" Gate)

The NOT gate is the simplest. It takes one input and flips it. If you give it a \(1\), it gives you a \(0\). If you give it a \(0\), it gives you a \(1\).

Boolean Expression: \( \text{NOT A} \)

Truth Table:

Input \(A = 0 \implies \text{Output} = 1\)
Input \(A = 1 \implies \text{Output} = 0\)

The AND Gate (The "Strict" Gate)

The AND gate is like a strict security guard. It only outputs a \(1\) if BOTH inputs are \(1\). If any input is \(0\), the output is \(0\).

Analogy: To start a car with a safety feature, you must have the Key Turned AND the Seatbelt Buckled.

Boolean Expression: \( \text{A AND B} \)

Quick Review: Only \(1 \text{ AND } 1\) results in \(1\). All other combinations result in \(0\).

The OR Gate (The "Generous" Gate)

The OR gate is more relaxed. It outputs a \(1\) if at least one of the inputs is \(1\). It only outputs a \(0\) if everything is \(0\).

Analogy: You can enter a cinema if you have a Paper Ticket OR a Digital Ticket on your phone. If you have both, you still get in!

Boolean Expression: \( \text{A OR B} \)

Key Takeaway: NOT flips the bit, AND needs all inputs to be \(1\), and OR needs at least one input to be \(1\).

2. The Secondary Gates (NAND, NOR, XOR)

Once you understand the basics, these secondary gates are just variations on a theme.

NAND and NOR (The Inverters)

NAND stands for "NOT AND." It is exactly what it sounds like: an AND gate with a NOT gate stuck on the end. It does the exact opposite of an AND gate.

NOR stands for "NOT OR." It does the exact opposite of an OR gate.

Did you know? NAND gates are famous because they are "universal." You can build any other type of gate using only NAND gates!

The XOR Gate (The "Strict OR")

XOR stands for Exclusive OR. This gate is the most common source of confusion, so pay close attention!

While a regular OR gate allows "both" inputs to be \(1\), the XOR gate says: "One or the other, but NOT both."

Analogy: Think of a menu where you can choose Soup XOR Salad. You get one, but you can't have both for the same price.

Boolean Expression: \( \text{A XOR B} \)

\(0 \text{ XOR } 0 = 0\)
\(0 \text{ XOR } 1 = 1\)
\(1 \text{ XOR } 0 = 1\)
\(1 \text{ XOR } 1 = 0\) (The "Exclusive" part!)

3. Truth Tables

A Truth Table is a mathematical table used to show all possible outcomes for a logic gate or circuit. It’s like a "cheat sheet" for the gate's behavior.

How to build a Truth Table for two inputs (\(A\) and \(B\)):
  1. List all possible combinations of \(1\)s and \(0\)s for the inputs. (Hint: for 2 inputs, there are always 4 combinations: \(00, 01, 10, 11\)).
  2. Calculate the result for each row based on the logic gate being used.
  3. Write the result in the output column.

Common Mistake: Students often forget the \(1, 1\) row in XOR. Just remember: XOR hates "both," so \(1 \text{ XOR } 1 = 0\).

4. Combining Logic Gates

In the real world, computers combine these gates to perform calculations. For example, a "Half Adder" (a circuit that adds two bits together) uses an XOR gate for the sum and an AND gate for the carry bit.

Solving Complex Boolean Expressions

If you see a long expression like \( \text{Output} = (\text{A AND B}) \text{ OR (NOT C)} \), solve it in steps:

  1. Solve the parts inside the brackets first.
  2. Solve the NOT parts.
  3. Solve the AND parts.
  4. Solve the OR parts last.

Example: If \(A=1, B=1, C=1\):
Step 1: \( (\text{1 AND 1}) = 1 \)
Step 2: \( \text{NOT 1} = 0 \)
Step 3: \( 1 \text{ OR } 0 = 1 \)
Final Output = \(1\)

Summary and Quick Review

Don't worry if this feels like a lot of \(1\)s and \(0\)s! Just keep these rules in your pocket:

  • NOT: Just flip it.
  • AND: Both must be \(1\).
  • OR: At least one must be \(1\).
  • XOR: Exactly one must be \(1\) (no "both" allowed).
  • NAND / NOR: Do the AND / OR logic, then flip the result.

Key Takeaway for Exam Success: When writing expressions, always use plain text as per the IB syllabus convention, such as \( \text{A AND NOT B} \). Always double-check your truth table rows to ensure you haven't missed any combinations!