Study Guide
Logic Expressions and Truth Tables
Working out exactly what a logic circuit does: listing every combination of three inputs, reading and writing logic expressions, and completing truth tables with working columns from a circuit, an expression or a description.
Lesson 2.3 Boolean Logic
For: Cambridge IGCSE Computer Science (ages 14 to 16), after Lessons 1 and 2; useful for AS level revision
Stage: Think
How many situations?
A school greenhouse has a fan. Its controller checks three things: is it too hot (A), is the roof window shut (B), and has the gardener pressed the override button (C)? Each is 1 or 0.
Think it through
How many different situations can the controller be in? How do you know you have them all?
- Hint 1: With two inputs there were four situations. What does a third input do to each of those four?
Show what happens
Eight. Each of the four situations for A and B can happen with C = 0 or with C = 1, so adding an input doubles the number: 2 × 2 × 2 = 8.
To list all eight without missing one, count in binary: 000, 001, 010, 011, 100, 101, 110, 111. C changes every row, B every two rows and A every four.
Check your understanding
Show the answer
Answer: B. A = 1, B = 0, C = 0
After 011 comes 100, just as 3 is followed by 4.
Stage: Discover
Writing a circuit down
Here is the greenhouse fan’s circuit.
Think it through
Describe in words what this circuit does, starting from the inputs on the left.
- Hint 1: Which two inputs go into the first gate, and what kind of gate is it?
- Hint 2: What happens to that gate’s output?
The same description can be written as a logic expression: Q = (A AND B) OR C. The brackets go round the gate that must be worked out first, the one nearest the inputs. A logic circuit and its expression describe exactly the same thing.
Check your understanding
Show the answer
Answer: C. Q = A OR (B AND C)
Brackets go round the first gate: here B AND C.
Stage: Experiment
Completing a circuit’s truth table
To complete a truth table for a circuit, work it out in the same order as the circuit: first each gate nearest the inputs, then the gates they feed. Each early gate gets its own working column.
- Working column first. The AND gate gets A = 1 and B = 1. AND gives 1 only when both inputs are 1, so A AND B is 1. Write 1 in the working column.
- Then the last gate. The OR gate gets the working column’s 1 and C = 0. OR gives 1 when at least one input is 1, so Q = 1.
It is too hot and the window is shut, so the fan runs even though nobody pressed the override. Change one fact, B to 0 (the window is open): A AND B becomes 0, and with C = 0 as well, Q becomes 0.
| A | B | C | A AND B (working) | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 0 | |
| 0 | 1 | 0 | 0 | |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 0 | 0 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | |
| 1 | 1 | 1 | 1 |
- Q is the OR of the working column and C: is at least one of them 1?
Show the completed table
| A | B | C | A AND B | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 |
Now a circuit with both columns blank. Do the working column first, all the way down, then Q.
| A | B | C | A OR B (working) | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | ||
| 0 | 0 | 1 | ||
| 0 | 1 | 0 | ||
| 0 | 1 | 1 | ||
| 1 | 0 | 0 | ||
| 1 | 0 | 1 | ||
| 1 | 1 | 0 | ||
| 1 | 1 | 1 |
- The working column is A OR B. Then Q is that column AND C.
Show the completed table
| A | B | C | A OR B | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
Think it through
In the second table, explain why Q is 0 in the row A = 1, B = 1, C = 0, even though both A and B are 1.
Show a model answer
A OR B is 1, but the AND gate also needs C, and C is 0. AND gives 1 only when both its inputs are 1, so Q is 0.
Stage: Check
The order matters
Check your understanding
Show the answer
Answer: A. Lee worked the gates in the wrong order: B AND C comes first, so Q = 1.
Brackets decide the order, just as in arithmetic. Working left to right and ignoring them is a common mistake in truth tables.
A working column is not optional decoration. Skipping it means holding the middle of the circuit in your head, and that is where most errors start. Work out the inner gate for every row first, then the next.
Stage: Experiment
From an expression to a truth table
Sometimes you are given only the expression: Q = (A OR B) AND NOT C.
Think it through
Which working columns will you need before you can work out Q?
- Hint 1: Look for every gate that is not the last one.
Show what happens
Two: A OR B, and NOT C. Q is then the AND of those two columns.
| A | B | C | A OR B (working) | NOT C (working) | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | |||
| 0 | 0 | 1 | |||
| 0 | 1 | 0 | |||
| 0 | 1 | 1 | |||
| 1 | 0 | 0 | |||
| 1 | 0 | 1 | |||
| 1 | 1 | 0 | |||
| 1 | 1 | 1 |
- NOT C is just C turned round in every row.
- Q is 1 only when both working columns are 1.
Show the completed table
| A | B | C | A OR B | NOT C | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
Stage: Apply
From a description to a truth table
A school alarm sounds (Q) if a door is opened (D) while the alarm is set (S), or if the panic button (P) is pressed.
Think it through
Which conditions must be true together, and which one works on its own?
- Hint 1: Which word joins the door and the setting?
Show what happens
The door being opened and the alarm being set must both be true (“while” means at the same time). The panic button works on its own.
Complete Q for every row from the description alone. The rows follow the inputs in alphabetical order: D, P, S.
| D | P | S | Q (alarm) |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 |
- Is the panic button pressed in this row? If so, the alarm sounds.
- If not, the alarm sounds only if the door is opened and the alarm is set.
Show the completed table
| D | P | S | Q (alarm) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Stage: Apply
A circuit to write and work out
Go deeper The two gates described in words
- Gate 1 takes inputs A and B: a curved back with a second curve just behind it, and a pointed front, with nothing on the output.
- Gate 2 takes the output of Gate 1 and input C: a flat back and a round front, with nothing on the output. Its output is Q.
Apply it
Show the answer
Answer: B. Q = (A XOR B) AND C
XOR first, then AND with C.
| A | B | C | A XOR B (working) | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | ||
| 0 | 0 | 1 | ||
| 0 | 1 | 0 | ||
| 0 | 1 | 1 | ||
| 1 | 0 | 0 | ||
| 1 | 0 | 1 | ||
| 1 | 1 | 0 | ||
| 1 | 1 | 1 |
Show the completed table
| A | B | C | A XOR B | Q |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 |
Stage: Consolidate
Show what you know
Think it through
Write the method you would use to complete the truth table for any circuit with three inputs, as numbered steps someone else could follow.
Show a model answer
- Write the eight input rows in binary counting order, 000 to 111. 2. Add a working column for each gate except the last, starting with the gates nearest the inputs. 3. Fill each working column all the way down. 4. Work out Q from the working columns and inputs it uses. 5. Check one row by tracing it through the circuit.
| A | B | C | B AND C (working) | NOT (B AND C) (working) | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | |||
| 0 | 0 | 1 | |||
| 0 | 1 | 0 | |||
| 0 | 1 | 1 | |||
| 1 | 0 | 0 | |||
| 1 | 0 | 1 | |||
| 1 | 1 | 0 | |||
| 1 | 1 | 1 |
Show the completed table
| A | B | C | B AND C | NOT (B AND C) | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
Think it through
Which kind of table is hardest for you: from a circuit, from an expression, or from a description? Why?
Show a model answer
There is no wrong answer. If it is descriptions, that is because you have to decide the gates yourself, and the next lesson starts exactly there.
- Three inputs give eight rows, in binary counting order from 000 to 111.
- A logic expression writes a circuit in words; brackets go round the gate worked out first.
- Use a working column for every gate before the last, and fill each one all the way down.
- The same method works from a circuit, an expression or a description.
Sources and scope
- What this lesson is. The third of four draft lessons on Boolean logic, written for this site, awaiting the site owner’s editorial review. Its curriculum links are provisional: the wording of each linked specification point has been checked against the published specification, but no link has yet been verified by the site owner. The links show where the lesson may help with a course; they do not imply that any examination board has reviewed or endorsed it.
- Original material. The greenhouse fan, the school alarm and Lee’s working are fictional examples written for this lesson.
- Notation. Expressions use the gate names in capitals with brackets, as the syllabus writes them; a single input after NOT is not bracketed (NOT C).
A logic gate whose output is 1 only when both of its inputs are 1.
The number system with only two digits, 0 and 1, in which each column is worth twice the column to its right.
Reasoning with values that are either true or false (1 or 0), combined with operations such as AND, OR and NOT.
A closed path that electricity flows around, made of connected components. A logic gate is a very small circuit, made of transistors.
A piece of information that goes into a system for it to use, such as whether a card is valid. In a logic gate each input is 0 or 1.
Logic gates joined together, so that the output of one gate becomes an input of another.
A written description of a logic circuit using gate names and brackets, such as Q = (A AND B) OR C.
A logic gate whose output is 1 when at least one of its inputs is 1, including when both are.
What a system produces from its inputs, such as whether a door unlocks. A logic gate has one output, 0 or 1.
A table listing every possible combination of a logic gate’s or circuit’s inputs, with the output for each.
An extra column in a truth table for the output of one gate inside a circuit, worked out before the gates that use it.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.