Skip to content
Tactiverge

Textbooks/Digital Logic and Computer Architecture/Chapter 2

2Logic gates and Boolean algebra

Version 1 · Technically checked (automated checks only) · 4 source lessons · 7 practice items

Text
All chapters and search
  1. 1. Information as bits
  2. 2. Logic gates and Boolean algebra
  3. 3. Combinational building blocks
  4. 4. Binary arithmetic
  5. 5. From silicon to switches
  6. 6. State machines and sequential logic
  7. 7. Instructions and the datapath
  8. 8. Performance and pipelining
  9. 9. The memory hierarchy
  10. 10. Power, performance and the chip

Introduction

A logic gate is a rule that turns input bits into an output bit. AND, OR and NOT are enough to describe any yes-or-no decision a machine makes, from a microwave door interlock to a sorting rule. Truth tables check every case; Boolean algebra and Karnaugh maps make the circuit smaller without changing what it does.

ABYY = A AND BABY000010100111
Figure 2.1. An AND gate and its truth table. An AND gate symbol with inputs A and B and output Y, beside a four-row truth table: A=0 B=0 gives Y=0, A=0 B=1 gives 0, A=1 B=0 gives 0, A=1 B=1 gives 1.

Explanation

This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

2.1 AND, OR, NOT: the three little deciders

A factory press only slams down if the worker has BOTH hands on the buttons. How does a machine check 'both'?

Inputs and outputs are bits

A logic gate takes one or two inputs, each 0 (off, false, no) or 1 (on, true, yes), and produces one output by following a fixed rule. In real circuits, 0 and 1 are low and high voltages; inside a lab simulation they are just numbers.

The three basic gates

  • AND: output 1 only when both inputs are 1. Both hands on the buttons.
  • OR: output 1 when at least one input is 1. Either doorbell button.
  • NOT: one input, and it flips it. 1 becomes 0, 0 becomes 1. Night light: ON when NOT bright.

Plus three useful extras

  • NAND = NOT AND: 0 only when both inputs are 1.
  • NOR = NOT OR: 1 only when both inputs are 0.
  • XOR (exclusive or): 1 when the inputs are different. Stairway light switches work like this.

Amazingly, NAND on its own can be wired up to make every other gate.

Common mix-ups

  • OR means one or the other, but not both.
    ✓ In logic, OR includes both: 1 OR 1 = 1. 'One or the other but not both' is XOR.

Open the full lesson: AND, OR, NOT: the three little deciders →

2.2 Logic gates and truth tables

Every decision your phone makes, from unlocking to sending a message, comes down to a few kinds of tiny switch. How few kinds?

Bits as voltages

Digital circuits treat a voltage near the supply (say 3.3 V or 5 V) as 1 and near 0 V as 0. Anything in between is avoided. Because only two levels matter, small amounts of noise do not change the answer.

The basic gates

NOT flips its input. AND gives 1 only if all inputs are 1. OR gives 1 if any input is 1. XOR gives 1 if the inputs differ. NAND and NOR are AND and OR followed by NOT. Engineers write them as ¬A, A·B, A + B and A ⊕ B.

A truth table says everything

List every input combination in counting order (00, 01, 10, 11) and write the output. That table completely defines the gate: two circuits with the same truth table do the same job, however different they look.

Gates are made of transistors

A transistor is a switch made from doped silicon (week 10): a voltage on one terminal lets current flow between the other two. Two transistors in series make a NAND-like path; in parallel, a NOR-like one. That is how a material property becomes logic.

Common mix-ups

  • OR means one or the other but not both.
    ✓ In logic, OR includes the case where both are 1. 'One but not both' is XOR.
  • Logic 1 always means exactly 5 V.
    ✓ It means 'near the high supply rail', which might be 5 V, 3.3 V or 1.8 V depending on the chip.

Open the full lesson: Logic gates and truth tables →

2.3 From safety rules to Boolean expressions

'The press may run only when the guard is shut, a hand is on each button and there is no fault.' Can you write that as one line of algebra?

Name the signals first

Give every input a letter and say what 1 means: G = 1 'guard closed', P = 1 'operator present', F = 1 'fault reported'. Writing what 1 means avoids the most common bug: a signal that is 1 when you thought it was 0.

Words to operators

'and', 'both', 'all' → ·. 'or', 'either', 'any' → +. 'not', 'no', 'unless' → ¬ (often 'X unless Y' becomes X · ¬Y). 'one or the other but not both' → ⊕. So the interlock is Y = G · P · ¬F.

Brackets carry meaning

AND binds tighter than OR, just as × binds tighter than +. A · B + C means (A · B) + C. If the rule says 'A and either B or C', write A · (B + C). When unsure, add brackets and check the truth table.

Check all three views

The expression is compact, the truth table is complete, and the gate diagram is what you build. If they disagree, one of them is wrong. For safety rules, read every row of the truth table aloud: 'guard open, operator present, no fault: machine off.'

Common mix-ups

  • A · B + C means A AND (B OR C).
    ✓ AND is done first: it means (A · B) + C. Use brackets to say otherwise.
  • If the expression looks right, the truth table must be right.
    ✓ Always check every row; mistranslated words often show up on just one or two rows.

Open the full lesson: From safety rules to Boolean expressions →

2.4 Module check: simplifying logic

A 'majority vote' circuit can be written with 12 letters, or with 6. Both give identical answers. Why would an engineer care which one you build?

Useful laws

Identity: A·1 = A, A + 0 = A. Null: A·0 = 0, A + 1 = 1. Complement: A·¬A = 0, A + ¬A = 1. Idempotent: A + A = A. Absorption: A + A·B = A. De Morgan: ¬(A·B) = ¬A + ¬B; ¬(A + B) = ¬A · ¬B. Each can be proved with a four-row truth table.

The Karnaugh map

A K-map is a truth table folded into a grid whose columns go 00, 01, 11, 10 (Gray code), so neighbouring cells differ in exactly one input. A group of two neighbouring 1s drops that input; a group of four drops two inputs. Cover every 1 with as few, as large groups as possible.

Always verify

A simplification is correct only if its truth table matches the original on every row. The explorer and the K-map both do this check for you; on paper, compare the two output columns.

Derivation: Two simplifications, step by step
  1. Distributive law (factor out A): A·B + A·¬B = A·(B + ¬B).

  2. Complement law: B + ¬B = 1, because exactly one of them is 1. So the expression is A·1 = A.

  3. De Morgan's law: ¬(A · B) = ¬A + ¬B and ¬(A + B) = ¬A · ¬B. Check by truth table: ¬(A·B) is 1,1,1,0 for AB = 00, 01, 10, 11, and so is ¬A + ¬B.

  4. Majority: the row-by-row form is ¬A·B·C + A·¬B·C + A·B·¬C + A·B·C. Copy A·B·C three times (X + X = X), pair it with each other term and use the complement law: (¬A + A)·B·C + A·(¬B + B)·C + A·B·(¬C + C) = B·C + A·C + A·B, 6 literals instead of 12.

Common mix-ups

  • Every expression can be simplified.
    ✓ Some, like three-input XOR, are already minimal as a sum of products.
  • K-map columns go 00, 01, 10, 11.
    ✓ They go 00, 01, 11, 10 so that neighbours differ in one input; otherwise groups do not simplify correctly.

Open the full lesson: Module check: simplifying logic →

Worked examples

AND, OR, NOT: the three little deciders: example 1

A safe opens only if the right code is entered AND the key is turned. The code is right (1) but the key isn't turned (0). Does it open?

Solution

AND needs both to be 1. 1 AND 0 = 0, so the safe stays shut.

Logic gates and truth tables: example 1

Write the truth table of A NAND B.

Solution

AND gives 0, 0, 0, 1 for AB = 00, 01, 10, 11. NOT flips each: NAND = 1, 1, 1, 0. It is 0 only when both inputs are 1.

From safety rules to Boolean expressions: example 1

'The fan runs if the temperature is high, unless the maintenance switch is on.' Write it as an expression.

Solution

Let T = 1 'temperature high' and M = 1 'maintenance switch on'. 'T unless M' = T · ¬M. Check: T = 1, M = 1 gives 0 (fan off for maintenance).

Module check: simplifying logic: example 1

Simplify A + A · B and check with a truth table.

Solution

Absorption: A + A·B = A·(1 + B) = A·1 = A. Truth table for AB = 00, 01, 10, 11: A + A·B = 0, 0, 1, 1, which is exactly A.

Interactive figures

Figure 2.2 from AND, OR, NOT: the three little decidersPick AND. Before flipping anything, predict the output for all four input combinations. Then check them. Do the same for OR and NOT. Which gate gives 1 most often?
Can't use the interactive? Read a description instead

The logic gate diagram lets you choose AND, OR, NOT, NAND, NOR or XOR, flip inputs A and B between 0 and 1, and see the output lamp. A truth table lists every input combination with its output and highlights the current row. AND gives 1 only for 1,1; OR gives 0 only for 0,0; NOT flips its one input.

Interactive figure (online). Description: The logic gate diagram lets you choose AND, OR, NOT, NAND, NOR or XOR, flip inputs A and B between 0 and 1, and see the output lamp. A truth table lists every input combination with its output and highlights the current row. AND gives 1 only for 1,1; OR gives 0 only for 0,0; NOT flips its one input.

Figure 2.3 from From safety rules to Boolean expressionsStart from the interlock preset A · B · ¬C (A = guard closed, B = operator present, C = fault). Toggle the inputs to find the only row where Y = 1. Then type A · (B + C) and compare it with A · B + C: find a row where they differ. Finally write your own rule for a door alarm and check its truth table.
Can't use the interactive? Read a description instead

The explorer takes a typed Boolean expression and shows three views: input switches with a live output, a gate diagram drawn from inputs on the left to the output on the right, and a full truth table with the current row marked. For the interlock A · B · ¬C, Y = 1 only on row 110: guard closed, operator present, no fault.

Interactive figure (online). Description: The explorer takes a typed Boolean expression and shows three views: input switches with a live output, a gate diagram drawn from inputs on the left to the output on the right, and a full truth table with the current row marked. For the interlock A · B · ¬C, Y = 1 only on row 110: guard closed, operator present, no fault.

Figure 2.4 from Module check: simplifying logicLoad the majority preset and compare the row-by-row form with the simplest form. Toggle cells to make Y = A: how many literals does it need? Load 'XOR of three' and explain why nothing groups. Finally make up a function with four 1s that simplifies to a single two-letter term.
Can't use the interactive? Read a description instead

The K-map shows eight cells in two rows (A = 0, 1) and four columns (BC = 00, 01, 11, 10). Pressing a cell toggles its output. The tool lists the groups and the simplest expression: majority (rows 3, 5, 6, 7) simplifies to A·B + A·C + B·C; rows 4 to 7 simplify to A; three-input XOR (rows 1, 2, 4, 7) does not simplify.

Interactive figure (online). Description: The K-map shows eight cells in two rows (A = 0, 1) and four columns (BC = 00, 01, 11, 10). Pressing a cell toggles its output. The tool lists the groups and the simplest expression: majority (rows 3, 5, 6, 7) simplifies to A·B + A·C + B·C; rows 4 to 7 simplify to A; three-input XOR (rows 1, 2, 4, 7) does not simplify.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

A microwave heats only if the door is shut and you pressed start. Which gate?

Practice 2

When does A XOR B output 1?

Practice 3

How many rows does the truth table of a 4-input gate have?

rows

Practice 4

Machine runs only if the guard is closed (G), the operator is present (P) and there is no fault (F = 1 means fault). Which expression?

Practice 5

'The light is on if it is dark (D), unless the switch is off (S = 1 means switch off).' Which expression?

Practice 6

By De Morgan's law, ¬(A + B) equals…

Practice 7

On a three-input K-map, four 1s form one group (a whole row or a 2 × 2 block). The resulting term has…

  1. A microwave heats only if the door is shut and you pressed start. Which gate?
    • OR
    • AND
    • NOT
    • XOR
  2. When does A XOR B output 1?
    • When both inputs are 1
    • When the inputs are different
    • When at least one input is 1
  3. How many rows does the truth table of a 4-input gate have? (rows)
  4. Machine runs only if the guard is closed (G), the operator is present (P) and there is no fault (F = 1 means fault). Which expression?
    • G + P + ¬F
    • G · P · F
    • G · P · ¬F
  5. 'The light is on if it is dark (D), unless the switch is off (S = 1 means switch off).' Which expression?
    • D + S
    • D · ¬S
    • ¬D · S
  6. By De Morgan's law, ¬(A + B) equals…
    • ¬A + ¬B
    • ¬A · ¬B
    • A · B
  7. On a three-input K-map, four 1s form one group (a whole row or a 2 × 2 block). The resulting term has…
    • Three literals
    • Two literals
    • One literal

Engineering applications

  • Safety interlocks

    A press may run only when both guards are closed AND the operator's two hands are on the buttons. Writing the rule as a Boolean expression lets you check all input cases before anyone stands near the machine.

  • Smaller circuits

    Simplifying an expression with Boolean laws or a Karnaugh map removes gates without changing the truth table. Fewer gates means less area, less power and fewer places for a fault.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

Introduces AND, OR, NOT and XOR, the building blocks behind every digital decision a computer makes.

10 min 7 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Boolean Logic & Logic Gates: Crash Course Computer Science #3 (CrashCourse)

Chapter summary

  • AND outputs 1 only when all inputs are 1; OR outputs 1 when any input is 1; NOT flips its input.
  • A truth table with n inputs has 2^n rows and fully defines a combinational circuit.
  • Turning words into logic starts with naming each signal and what 1 means for it.
  • De Morgan's laws: NOT(A AND B) = (NOT A) OR (NOT B), and NOT(A OR B) = (NOT A) AND (NOT B).
  • Any simplification must be checked against the original truth table.

Glossary

Truth table
A truth table lists the output of a logic function for every possible combination of its inputs; n inputs need 2^n rows.
AND gate
An AND gate outputs 1 only when all of its inputs are 1.
OR gate
An OR gate outputs 1 when at least one of its inputs is 1.
NOT gate (inverter)
A NOT gate has one input and outputs its opposite: 0 becomes 1 and 1 becomes 0.
XOR gate
An XOR gate outputs 1 when its inputs are different and 0 when they are the same.
De Morgan's laws
NOT (A AND B) equals (NOT A) OR (NOT B), and NOT (A OR B) equals (NOT A) AND (NOT B).

Definitions from the Field Guide.

Project: Specify a three-sensor interlock

A conveyor must stop if a light curtain is broken, OR if the cover is open while the belt is running. Name the signals, write the expression, build the full truth table, simplify it and show the simplified version gives the same table.

Deliverables

  • Signal names with what 1 means for each
  • The full truth table
  • The simplified expression with each law used
  • A row-by-row check that both versions agree

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • Claude E. Shannon (1938). "A Symbolic Analysis of Relay and Switching Circuits". Transactions of the American Institute of Electrical Engineers 57(12), 713–723.
  • Maurice Karnaugh (1953). "The Map Method for Synthesis of Combinational Logic Circuits". Transactions of the American Institute of Electrical Engineers, Part I: Communication and Electronics 72(5), 593–599.
  • David Money Harris and Sarah L. Harris (2012). Digital Design and Computer Architecture, 2nd edition. Morgan Kaufmann.

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.