Cambridge A‑Level Computer Science (9618) – 3.2 Logic Gates and Logic Circuits
Context within the Syllabus
This note forms part of the Logic Gates and Logic Circuits unit (Section 3.2) and links to several other syllabus sections:
- 1 Information representation – binary, hexadecimal, BCD and character encodings are the foundation for the input values used in truth tables.
- 3 Hardware – combinational vs. sequential circuits, adders, multiplexers, decoders.
- 4 Processor fundamentals – control‑unit micro‑operations and ALU control signals are specified with truth tables.
- 9 Algorithm design & problem‑solving – constructing a truth table is an algorithmic process; pseudocode is provided later.
- 11 Programming – Boolean expressions in code can be verified against a truth table.
- A‑Level extensions (optional) – decision‑tree evaluation (AI), simple encryption (XOR), and parallel‑processing control logic all rely on Boolean logic.
Learning Objective
Construct accurate truth tables for any Boolean expression, use them to design, verify and test combinational logic circuits, and relate the tables to higher‑level topics such as processor control, algorithm design and programming.
1. Prerequisite Knowledge
- Binary and other number systems – bits, binary counting, two’s‑complement, hexadecimal, BCD, ASCII and Unicode character codes.
- Basic Boolean algebra – symbols ∧ (AND), ∨ (OR), ¬ (NOT), ⊕ (XOR) and the notion of a Boolean function.
- Logic‑gate symbols – recognise the standard schematic symbols for NOT, AND, OR, NAND, NOR and XOR.
2. Why Truth Tables Matter
- Provide an exhaustive, systematic check of a circuit’s behaviour for every possible input combination.
- Serve as the starting point for:
- Simplifying Boolean expressions (Karnaugh maps, algebraic reduction).
- Designing combinational circuits (adders, multiplexers, decoders, control units).
- Testing and debugging digital systems in the practical exam (Paper 4).
- Demonstrate functional completeness – any Boolean function can be built using only NAND gates or only NOR gates.
- Bridge to other topics:
- Control‑unit micro‑operations are described with truth tables.
- Boolean expressions in programming (e.g.,
if (A && B) || !C) can be verified against a table.
- Simple packet‑filter rules in networking are Boolean conditions that can be modelled with truth tables.
3. The Six Basic Logic Gates (Syllabus Requirement)
| Gate |
Symbol |
Boolean expression |
Truth table |
| NOT |
∼ |
¬A |
|
| AND |
∧ |
A ∧ B |
|
| OR |
∨ |
A ∨ B |
|
| NAND |
⎯∧ |
¬(A ∧ B) |
|
| NOR |
⎯∨ |
¬(A ∨ B) |
|
| XOR |
⊕ |
A ⊕ B |
|
Note: Because NAND and NOR are functionally complete, any Boolean function can be built using only NAND gates or only NOR gates – a common requirement in Paper 4 practical tasks.
4. General Procedure for Constructing a Truth Table
- Identify distinct input variables (e.g., A, B, C).
- Calculate the number of rows: with n inputs you need 2ⁿ rows.
- List binary combinations in the input columns, using binary counting from
000…0 to 111…1.
- Break the expression into sub‑expressions (parentheses, intermediate gates). Create a column for each sub‑expression – this mirrors the actual circuit and reduces errors.
- Evaluate each row step‑by‑step, filling the intermediate columns before the final output.
- Cross‑check that the final column matches the intended behaviour of the whole circuit.
5. Worked Example 1 – Mixed Gates
Construct a truth table for F = (A ∧ B) ∨ ¬C.
| A | B | C | A∧B | ¬C | F = (A∧B) ∨ ¬C |
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
Observation: F is 0 only when A∧B = 0 and C = 1. This insight is useful for later simplification.
6. Worked Example 2 – Half‑Adder
A half‑adder adds two single‑bit numbers A and B. Outputs:
- Sum = A ⊕ B (XOR)
- Carry = A ∧ B (AND) – the more complex expression
¬(A⊕B) ∧ (A∨B) reduces to this.
| A | B | Sum = A⊕B | Carry = A∧B |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
The circuit consists of an XOR gate (Sum) feeding into the output and an AND gate (Carry). The same pattern recurs in full‑adders, multiplexers and many ALU control units.
7. From Truth Table to Circuit (Design Checklist)
- Identify every column that represents a gate output.
- Draw the corresponding gate symbol; label its inputs with the appropriate variable or intermediate column.
- Connect intermediate outputs to downstream gates exactly as indicated by the table.
- Verify that the final output column matches the behaviour of the drawn circuit.
- If the circuit is sequential (e.g., includes flip‑flops), add clock and feedback lines – this note focuses on combinational logic only.
Example circuit for F = (A ∧ B) ∨ ¬C:
- AND gate: inputs A, B → output A∧B
- NOT gate: input C → output ¬C
- OR gate: inputs A∧B and ¬C → final output F
8. Linking Truth Tables to Later Topics
- Combinational circuit design: Truth tables precede Karnaugh‑map minimisation and gate‑level synthesis.
- Processor design: Control‑unit micro‑operations (e.g., “load IR”, “increment PC”) are described by truth tables that generate control signals.
- Practical exam (Paper 4): You may be asked to implement a given truth table using only NAND or only NOR gates – recall functional completeness.
- Networking & security: Packet‑filter rules and simple access‑control policies are Boolean conditions that can be modelled with truth tables.
- Programming: Translate a Boolean expression into an
if statement and verify its correctness with the table.
- A‑Level extensions (optional): Decision‑tree evaluation in AI, XOR‑based stream ciphers, and parallel‑processing control logic all rely on the same Boolean foundations.
9. Practice Exercise
Construct a complete truth table for the Boolean expression below and then sketch the corresponding logic circuit.
G = ¬(A ∨ B) ∧ (B ⊕ C)
Steps
- List the three inputs (A, B, C). You will need 2³ = 8 rows.
- Create intermediate columns for:
A ∨ B
¬(A ∨ B)
B ⊕ C
- Final output
G
- Fill the table row‑by‑row using the gate truth tables from Section 3.
- Translate each intermediate column into a gate:
A ∨ B → OR gate
- ¬(A ∨ B) → NOT gate (after the OR)
B ⊕ C → XOR gate
- Final ∧ → AND gate combining the NOT output and the XOR output.
Suggested Solution (Self‑Check)
| A | B | C | A∨B | ¬(A∨B) | B⊕C | G = ¬(A∨B) ∧ (B⊕C) |
| 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
The resulting circuit uses one OR gate, one NOT gate, one XOR gate and one AND gate – exactly the gates listed in the syllabus.
10. Algorithmic Generation of a Truth Table (Programming Exercise)
Write pseudocode that, given any Boolean expression in infix notation, outputs its full truth table. This reinforces the link between algorithm design and digital logic.
Algorithm GenerateTruthTable(expr):
inputs ← list of distinct variables in expr
n ← length(inputs)
rows ← 2ⁿ
Print header: inputs + sub‑expressions + final result
for i from 0 to rows‑1 do
// binary counting to assign values
for j from 0 to n‑1 do
inputs[j] ← (i >> (n‑1‑j)) & 1
end for
// evaluate sub‑expressions in order of parentheses
result ← evaluate(expr, inputs)
Print inputs and result
end for
end Algorithm
In an exam you won’t be asked to code this, but understanding the systematic nature of the algorithm helps avoid mistakes when constructing tables manually.
11. Quick Reference Checklist
- Count inputs → rows = 2ⁿ.
- Write inputs in binary order (000… to 111…).
- Add a column for every sub‑expression (parentheses, intermediate gates).
- Use the gate truth tables (Section 3) to fill intermediate columns.
- Final column = overall expression.
- Cross‑check the final column against a hand‑drawn circuit or a simple program.
12. Further Reading / Extension Activities (Optional)
- Decision trees (AI): each node evaluates a Boolean condition – truth tables can be used to verify the tree’s logic.
- Simple encryption: the XOR gate is the core of many stream ciphers; construct truth tables for encrypt/decrypt functions.
- Parallel processing control: design a truth table for a basic pipeline stall detector (e.g., “if (RegWrite && MemRead) …”).
- Flip‑flops and sequential logic: extend the current combinational approach to include clocked elements – see the “Sequential circuits” section of the syllabus.
Mastering truth tables equips you with a universal tool for analysing, designing, and testing all digital systems covered in the Cambridge A‑Level Computer Science syllabus, and provides a solid bridge to programming, processor design, networking and beyond.