Cambridge AS & A Level · Part 1 · Chapter 4
Logic Gates and Logic Circuits
How a TRUE/FALSE question becomes a logic expression, a circuit of gates and a truth table, and how to turn any one of those into the others. Every figure, task and exam question from the chapter is here, with live circuits to try each idea.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- use the symbols for the NOT, AND, OR, NAND, NOR and XOR gates
- understand and define what each of these gates does
- Construct the truth table for each gate
- construct a logic circuit from a problem statement, a logic expression or a truth table
- construct a truth table from a problem statement, a logic circuit or a logic expression
- construct a logic expression from a problem statement, a logic circuit or a truth table
🗺️ One idea, four ways of writing it
The whole chapter is about one situation described in four interchangeable forms. Each later tab practises one of the conversions.
| Form | What it looks like | Example |
|---|---|---|
| Problem statement | Everyday words | Take an umbrella if it is raining or rain is forecast. |
| Logic expression | Propositions joined by Boolean operators | X = A OR B |
| Logic circuit | Gate symbols joined by wires | An OR gate with inputs A and B |
| Truth table | Every input combination with its output | 00→0, 01→1, 10→1, 11→1 |
💬 4.01 Boolean logic and problem statements
Suppose someone asks whether Colombo is further north than Singapore. If you know a little geography, you answer yes or no. You could just as well say the statement is TRUE or FALSE: in logic, those are the only two possible values.
Real decisions usually depend on more than one proposition:
- I will take an umbrella if it is raining or the forecast says rain.
- The air-conditioning should run during working hours and when the temperature is above 25 °C.
Each of these is a problem statement: an informal description of an outcome. The words or and and are doing logical work, joining two propositions.
🧪 Spot the proposition
A logic proposition has to be something that is definitely TRUE or definitely FALSE at a given moment. Questions, commands and opinions are not propositions. Check yourself:
🎮 Proposition or not?
⚙️ 4.02 Boolean operators
The words that join propositions become Boolean operators, named after the mathematician George Boole. Three of them do all the work:
| Operator | Definition |
|---|---|
| A AND B | TRUE if A is TRUE and B is TRUE |
| A OR B | TRUE if A is TRUE or B is TRUE (or both) |
| NOT A | TRUE if A is FALSE |
Using them, the two problem statements from 4.01 can be written more formally:
Take_umbrella = TRUE IF (raining = TRUE) OR (rain_forecast = TRUE)
Aircon_on = TRUE IF (working_hours = TRUE) AND (temperature > 25)
Any logic expression at all can be written with only AND, OR and NOT. Even so, three more operators are useful:
| Operator | Definition | Think of it as |
|---|---|---|
| A NAND B | TRUE if A is FALSE or B is FALSE | NOT (A AND B) |
| A NOR B | TRUE if A is FALSE and B is FALSE | NOT (A OR B) |
| A XOR B | TRUE if exactly one of A and B is TRUE | "one or the other, not both" |
🛒 Worked Example 4.01 Problem statement → expression
A shopkeeper has new stock delivered at the end of every month. A delivery is also made early in two situations: when the stock of an item falls to its re-order level, or when a regular customer places an order for a large amount.
Step 1: name the propositions.
| Symbol | Proposition |
|---|---|
| A | It is the end of the month |
| B | The re-order level has been reached |
| C | The order is from a regular customer |
| D | The order is for a large amount |
Step 2: join them. Any one of three things triggers a delivery, so they are joined with OR. The third one needs both C and D, so it is bracketed with AND:
X = A OR B OR (C AND D)
✏️ Task 4.01
Let A = the document is covered by copyright and B = permission has been obtained.
X = NOT A OR (A AND B)
Check the truth table below: X is 0 only when A = 1 and B = 0. That means the expression simplifies to NOT A OR B, but writing it the long way, straight from the statement, is fine.
🎮 Problem statement → expression
Read the situation and choose the expression that matches it exactly. Watch the brackets.
📊 4.03 Truth tables
A truth table lists every possible combination of input values and the output each one produces. In a truth table, 1 stands for TRUE and 0 for FALSE. Here is the table for A AND B:
Table 4.01 · the truth table for A AND B
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Only the last row has both inputs TRUE, so it is the only row with an output of 1.
✏️ Task 4.02
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Any row with at least one 1 gives 1. Only 00 gives 0.
🎮 Fill in the truth table
A new expression every time. Tap each output cell to set it to 0 or 1, then check. Work out the brackets first.
🔌 4.04 Logic circuits and logic gates
Inside a computer, a logic proposition is a signal that is either on (1) or off (0). A logic circuit combines these signals using components called logic gates, each one acting like a Boolean operator.
Every gate has its own symbol. The shape tells you which gate it is; the inputs come in on the left and the output leaves on the right. Here is the AND gate:
Figure 4.01 (redrawn) · the symbol for an AND gate
A gate can be built with more than two inputs, but in this course every gate has at most two.
🔣 All six gates Figure 4.02
- The NOT gate has only one input. Its output is the opposite of that input.
- A NAND gate gives the same result as an AND gate followed by a NOT gate. The small circle (bubble) on its output means "invert".
- A NOR gate gives the same result as an OR gate followed by a NOT gate.
- XOR is the OR shape with an extra curved line at the back.
🔬 Lab: gate explorer
Choose a gate, then toggle its inputs. The lit wires carry 1, and the current row of the truth table lights up.
✏️ Task 4.03 and Extension Question 4.01
Toggle both circuits: for every row the outputs match. P is the output of the AND gate.
No. NOT A AND NOT B is 1 only when both inputs are 0. That is the NOR truth table. NAND is 1 for 00, 01 and 10. The two differ for inputs 01 and 10.
The rule that does work is NOT (A AND B) = NOT A OR NOT B. You will meet this again as De Morgan's law in Chapter 19.
❓ Question 4.01
| Gate | Symbol | Output is 1 when… |
|---|---|---|
| NOT | Triangle with a bubble, one input | the input is 0 |
| AND | Flat back, D-shaped front | both inputs are 1 |
| OR | Curved back, pointed front | at least one input is 1 |
| NAND | AND shape with an output bubble | at least one input is 0 |
| NOR | OR shape with an output bubble | both inputs are 0 |
| XOR | OR shape with an extra curve at the back | exactly one input is 1 |
🎮 Name that gate
Identify the gate from its symbol.
🎮 Which gate behaves like this?
Identify the gate from its truth table or its definition.
🏦 Worked Example 4.02 Statement → expression → circuit
A bank offers a special interest rate. To get it, a customer must have banked there for at least two years. They must also meet at least two of these three conditions: they are married, they are aged 25 or over, and at least one of their parents banks there.
Step 1: the propositions.
| Symbol | Proposition |
|---|---|
| A | A customer for two years or more |
| B | Married |
| C | Aged 25 or over |
| D | A parent is a customer |
Step 2: the expression. "Two of B, C and D" means B AND C, or B AND D, or C AND D. A is needed as well:
X = A AND (((B AND C) OR (B AND D)) OR (C AND D))
The extra brackets are there because each gate has only two inputs, so the three ORs have to be done one pair at a time.
Step 3: the circuit. Each AND or OR in the expression becomes one gate, so the circuit needs four AND gates and two OR gates.
Here it is live. P, Q and R are the three AND pairs; S and T are the two OR gates.
🔬 Lab: expression → circuit
Type any logic expression using up to four letters and the operators AND, OR, NOT, NAND, NOR, XOR and brackets. You will get its circuit and its truth table. NOT is applied first, then AND, then XOR, then OR, so use brackets if you mean something else.
🔍 Worked Example 4.03 Circuit → truth table
Find the truth table for this circuit:
Step 1: set up the table. Three inputs give eight rows. Leave a workspace between the inputs and the output for the values partway through the circuit:
| Inputs | Workspace | Output | |||||
|---|---|---|---|---|---|---|---|
| A | B | C | M | N | P | Q | X |
| 0 | 0 | 0 | |||||
| … and so on to 111 | |||||||
Table 4.02 · the empty table with its workspace
Step 2: label the intermediate points. Each gate output gets a letter:
- M = A AND B
- N = NOT B
- P = NOT M
- Q = N AND C
- X = P AND Q
Step 3: fill in the columns from left to right. Each workspace column only needs columns already filled in. Toggle the inputs to watch the values flow, then compare with the finished table:
X is 1 only for inputs 001 and 101.
🎮 Trace a mystery circuit
A new random circuit each time. Trace each row through the gates (write the workspace values on paper), then fill in the output column and check.
🔁 Truth table → logic expression
To write an expression from a truth table, use only the rows where the output is 1:
- For each of those rows, AND the inputs together, putting NOT in front of any input that is 0.
- OR all of those terms together.
Table 4.04 · a truth table to turn into an expression
| A | B | C | X |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Rows 001, 011 and 100 give 1, so:
X = (NOT A AND NOT B AND C) OR (NOT A AND B AND C) OR (A AND NOT B AND NOT C)
This is correct but long. Chapter 19 shows how to simplify expressions like this one.
🔌 Logic circuit → logic expression
There are two ways to do this:
- Build the truth table for the circuit (as in the Circuit → truth table tab), then use the rows with output 1 as above.
- Or work backwards from the output, writing each gate as an operator with its two inputs in brackets. For Figure 4.05 this gives X = NOT (A AND B) AND (NOT B AND C).
✏️ Task 4.04
X = (NOT A OR NOT B) AND C
P is NOT A OR NOT B, which is the same as A NAND B. The light is on for inputs 001, 011 and 101.
🎮 Truth table → expression
Write any expression that gives this truth table. The answer is auto-marked by testing every row, so a simplified version counts too. Type AND, OR, NOT and brackets, with spaces between words.
🎮 Circuit → expression
Which expression describes this circuit? Read it backwards from X.
📌 Summary
- A logic scenario can be described by a problem statement or by a logic expression.
- A logic expression is made of logic propositions joined by Boolean operators.
- A logic circuit is built from logic gates, and each gate works like one Boolean operator.
- The outcome of a logic expression or logic circuit can be set out as a truth table.
- A logic expression can be built from a truth table by using the rows that give an output of 1.
🪞 Reflection Point
That a problem statement, a logic expression, a logic circuit and a truth table are four ways of writing the same logic, and you can always get from any one of them to any other. The truth table is the common ground: if two versions give the same truth table, they are equivalent.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my own mark-scheme-style answers, not official mark schemes. Where the answer is a circuit, it is live: toggle the inputs to check it.
(i) Gate 1: OR. Gate 2: NAND. Gate 3: NOT.
(ii) Either table:
| A | B | OR | NAND |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 |
(i) P = A AND B, Q = B AND C, R = P OR Q, X = R OR C:
| A | B | C | P | Q | R | X |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
(ii) The B AND C gate is redundant. Whenever its output is 1, C must be 1, and C already goes straight to the final OR gate, which makes X = 1 anyway. Removing the gate leaves X = (A AND B) OR C with the same truth table.
| A | B | X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
(i) A = the team wins match 1. B = the team wins match 2. C = the team has the higher total score.
(ii) "Wins one and loses the other" is exactly what XOR means:
X = (A AND B) OR ((A XOR B) AND C)
Also accepted: (A AND B) OR (A AND NOT B AND C) OR (NOT A AND B AND C).
(iii)
| Signal | Value | Condition |
|---|---|---|
| A | 0 | Water flow in the radiators is too low |
| 1 | Water flow in the radiators is within limits | |
| B | 0 | Hot water tank temperature is too high |
| 1 | Hot water tank temperature is within limits | |
| C | 0 | Water level in the hot water tank is too low |
| 1 | Water level in the hot water tank is within limits |
Too low means C = 0 and too high means B = 0, so X = NOT B AND NOT C. A does not affect the output.
(i)
| A | B | C | X |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
(ii) B and C each go through a NOT gate, then into an AND gate. (A NOR gate on B and C would also do the job.)
B = 1, A = 0 and C = 0, so X = B AND NOT A AND NOT C. Only input 010 gives 1.
X = (A OR NOT B) OR (B AND NOT C)
P = A OR NOT B, Q = B AND NOT C:
| A | B | C | P | Q | X |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
X is 0 only for input 011.
Work backwards from X: the final AND gate takes NOT C and the output of an OR gate, which joins (NOT A AND B) with (NOT B OR C).
X = ((NOT A AND B) OR (NOT B OR C)) AND NOT C
Cambridge International AS & A Level Computer Science 9608, Paper 13 Q6, June 2015
X = (NOT B AND NOT S) OR (NOT P AND S)
Three NOT gates, two AND gates and one OR gate. In the circuit below the second AND gate takes S on top, which is the same thing.
J = NOT B AND NOT S, K = NOT P AND S:
| B | S | P | J | K | X |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 |
Cambridge International AS & A Level Computer Science 9608, Paper 12 Q1, November 2016
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 4 Logic Gates and Logic Circuits · Figures from the Cambridge coursebook (Langfield & Duddell)