Syllabus coverage
- Identify and use the standard symbols for logic gates
- Define and understand the functions of NOT, AND, OR, NAND, NOR and XOR (EOR)
- Use logic gates to create a given logic circuit from a problem statement, a logic expression or a truth table
- Complete a truth table from a problem statement, a logic expression or a logic circuit
- Write a logic expression from a problem statement, a logic circuit or a truth table
- Work with circuits of up to three inputs and one output, drawn as given without simplification
Part of the O Level Computer Science syllabus 2210.
Binary inputs, binary outputs
A logic gate is a circuit that takes one or two binary inputs and produces one binary output. The inputs and the output are 0 or 1, which stand for FALSE and TRUE, off and on, low and high. Because the values are binary, the behaviour of a gate can be written out completely: there are only a few possible combinations of inputs, and each one has a fixed output.
Gates are the hardware behind the logical operators in a program. When a program tests `IF Armed = TRUE AND DoorOpen = TRUE`, the processor is using the same AND function that the gate performs, and when a circuit decides whether to sound an alarm, it combines sensor signals with gates in exactly the way the program combines conditions.
Two conventions run through the topic. A circuit in this syllabus has at most three inputs and exactly one output, and circuits are drawn as the problem describes them, without simplification. If a statement asks for `(A AND B) OR C`, the answer has three gates in that arrangement, even if a shorter circuit could produce the same output.
| Value | Means | Also written as |
|---|---|---|
| 1 | TRUE, on, high voltage | Set, asserted |
| 0 | FALSE, off, low voltage | Clear, not asserted |
NOT: the inverter
NOT is the only gate in the syllabus with a single input. Its output is the opposite of its input: a 1 becomes a 0 and a 0 becomes a 1. The symbol is a triangle with a small circle on the output, and the circle is the part that means 'inverted'.
In an expression it is written `NOT A`, and in a truth table it has only two rows because there is only one input. If a sensor gives 0 while a door is closed, `NOT` on that sensor gives 1 while the door is closed, which is how a circuit can be built for 'the alarm sounds when the door is not closed'.
Do not confuse NOT with a gate that has two inputs and happens to invert one of them. NOT has one input and one output, full stop.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
AND: both inputs must be 1
AND has two inputs and gives 1 only when both inputs are 1. In every other case the output is 0. The symbol is a D shape with a straight back and a curved front.
AND is the gate for conditions that must all be met. A car's warning light that comes on when the door is open AND the engine is running needs an AND gate, because either condition alone must not light it. In a program the same rule is written with the keyword AND, and the truth table is the definition of what that keyword does.
It is worth memorising the shape of the table rather than the sentence: one row of the four has a 1, and it is the bottom row, where both inputs are 1.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR: at least one input is 1
OR has two inputs and gives 1 when at least one of them is 1. It gives 0 only when both inputs are 0. The symbol is a curved shape with a pointed output, like an arrowhead with a curved back.
OR is the gate for alternatives. An alarm that sounds when the door sensor OR the window sensor is triggered needs an OR gate, because either sensor on its own is enough. Note that OR also gives 1 when both inputs are 1 - it is not 'one or the other but not both'. That exclusive version is a different gate, XOR.
Again, learn the table by its shape: three of the four rows have a 1, and the only 0 is the top row.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
NAND and NOR: AND and OR with the output inverted
NAND is AND followed by NOT. Its output is the opposite of AND, so it gives 0 only when both inputs are 1, and 1 in every other case. The symbol is the AND shape with a small circle on the output. The name says it: Not AND.
NOR is OR followed by NOT. Its output is the opposite of OR, so it gives 1 only when both inputs are 0, and 0 in every other case. The symbol is the OR shape with a circle on the output.
The circle is the whole difference between the pairs, and it is where most marks are lost. Read the symbol carefully: a D shape with a circle is NAND, a curved arrowhead with a circle is NOR. If you can state AND and OR, you can derive NAND and NOR by inverting every output - which is also a safe way to check an answer under pressure.
| A | B | A NAND B | A NOR B |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
XOR: the inputs must be different
XOR (also written EOR, exclusive OR) gives 1 when the two inputs are different, and 0 when they are the same. So 0 and 1 gives 1, 1 and 0 gives 1, but 0 and 0 gives 0 and 1 and 1 gives 0. The symbol is the OR shape with an extra curved line behind the input side.
XOR is the gate for 'one or the other but not both'. A stair light controlled from two switches uses XOR: the light is on when exactly one switch is up. It is also the gate behind binary addition without the carry, because the sum bit of 1 + 1 is 0 with a carry, which is exactly what XOR gives.
The contrast with OR is the examinable point. OR gives 1 for three rows out of four; XOR gives 1 for two. Both give 1 when the inputs differ, but only OR gives 1 when both are 1.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The six gates side by side
The whole topic rests on this one table. Learn the description of each gate, the shape of its symbol and the pattern of its output column, and every question becomes a matter of applying them in order.
For a circuit with more than one gate, work out the output of each gate in turn and label the wire between gates with its value. A three-input circuit has two gates feeding a third, so there are two intermediate values before the final output. Writing them down is not extra work - it is what stops the last gate being fed the wrong input.
| Gate | Output is 1 when | Rows with output 1 (of four) |
|---|---|---|
| NOT | the single input is 0 | one of two |
| AND | both inputs are 1 | one of four |
| OR | at least one input is 1 | three of four |
| NAND | the inputs are not both 1 | three of four |
| NOR | both inputs are 0 | one of four |
| XOR | the inputs are different | two of four |
Building a truth table
A truth table lists every possible combination of inputs and the output for each. For n inputs there are 2^n rows: two rows for one input, four for two inputs, eight for three. A three-input table has eight rows, and a table with only four is wrong however good the logic is.
The rows follow a fixed order so that no combination is missed. The rightmost input column alternates every row: 0, 1, 0, 1 and so on. The next column to the left changes every two rows, and the leftmost changes every four. For three inputs the first column is 0000 1111, the second 0011 0011 and the third 0101 0101, which gives 000, 001, 010, 011, 100, 101, 110, 111.
Add a column for each intermediate point in the circuit before the output column. For `X = (A AND B) OR NOT C`, work out `A AND B` in one column and `NOT C` in another, then OR the two columns into X. Each final value is then a single, small step from two values you can see, instead of a guess.
Completing a table from a circuit uses the same columns, filled by following the wires from left to right. Completing one from a problem statement needs one extra step: decide which inputs the statement names, then write the condition for each row in words before turning it into 0 or 1.
From words to a circuit, and back
A problem statement gives the conditions in English, and you turn them into gates. Identify the inputs first - each sensor or switch is one input - then find the connecting words. AND joins conditions that must both hold, OR joins alternatives, and NOT applies to a single condition that must not hold. Brackets in the resulting expression tell you which gate feeds which.
'The alarm sounds when the system is armed and either the door or the window is open' has three inputs: Armed, Door, Window. 'Either ... or' is an OR between Door and Window, and 'and' joins that result to Armed, so the expression is `Alarm = Armed AND (Door OR Window)`. The brackets are not decoration: without them the expression would mean something else.
Going the other way, from a circuit to an expression, label every wire. Give each gate output a name or write the expression for it beside the gate, starting with the gates nearest the inputs. The last gate gives the whole expression, and any group that feeds a single input must be bracketed.
From a truth table to an expression, find the rows where the output is 1. Each such row becomes a term joining the inputs with AND, using NOT for any input that is 0 in that row; the terms are then joined with OR. A table with one row of 1 gives one term; a table with three gives three. No simplification is expected, so write the terms as they fall out of the rows.
- Name the inputs before anything else - one input per sensor, switch or condition.
- AND for conditions that must all hold; OR for alternatives; NOT for a condition that must not hold.
- Bracket any group of gates that feeds a single input of another gate.
- From a truth table, write one AND term for each row with output 1, then OR the terms together.
Checking your answer
Every logic answer can be checked, because the number of input combinations is small. Pick a row - usually the one where all inputs are 1, then the one where all are 0 - and follow it through the circuit or expression by hand. If the result does not match your table, the table is wrong.
Check the gate count too. A circuit built from a three-input expression written without simplification has one gate for each operator plus one for each NOT. `(A AND B) OR NOT C` needs three gates: AND, NOT and OR. If your drawing has two gates, an operator has been lost; if it has five, something has been invented.
Finally, check the direction words. NAND and NOR are the pairs most often swapped, and XOR is most often confused with OR. A quick test on the row where both inputs are 1 separates them all: AND and OR give 1, NAND and XOR give 0, NOR gives 0 and NOT does not apply.
| Test row | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|
| A = 0, B = 0 | 0 | 0 | 1 | 1 | 0 |
| A = 1, B = 1 | 1 | 1 | 0 | 0 | 0 |
Key terms you must be able to define
- Logic gate
- A circuit with one or two binary inputs and one binary output, whose output is fixed by the combination of inputs.
- Boolean
- A value that is either TRUE or FALSE, written as 1 or 0 in a logic circuit.
- Truth table
- A table listing every possible combination of inputs and the output for each; it has 2^n rows for n inputs.
- NOT
- The single-input gate that inverts its input: 0 becomes 1 and 1 becomes 0.
- AND
- The gate that outputs 1 only when both inputs are 1.
- OR
- The gate that outputs 1 when at least one input is 1, and 0 only when both are 0.
- NAND
- AND with the output inverted: it outputs 0 only when both inputs are 1.
- NOR
- OR with the output inverted: it outputs 1 only when both inputs are 0.
- XOR (EOR)
- Exclusive OR: it outputs 1 when the two inputs are different and 0 when they are the same.
- Logic expression
- A statement of a circuit using the gate names and brackets, such as X = (A AND B) OR NOT C.
In context
2210 sets its questions inside systems a student already uses - a school network, a phone, a supermarket till, a vending machine, a website. These show how the theory is applied to a context you have not seen before, then you answer for the system you are given.
The warning light comes on when the ignition is on AND the driver's seat is occupied AND the belt is not fastened. With inputs Ignition, Occupied and BeltFastened, the expression is `Light = Ignition AND Occupied AND NOT BeltFastened`. The NOT applies to the belt sensor alone, so it is bracketed with that input, not with the whole expression.
The alarm sounds when the system is armed and either the door or a window is opened: `Alarm = Armed AND (Door OR Window)`. Two sensors feed an OR gate, and its output feeds an AND gate with Armed. It is a three-input circuit with three gates, drawn exactly as the statement reads and not simplified.
A light controlled by a switch at the bottom and a switch at the top is on when exactly one switch is up, so the two switch signals feed an XOR gate. Both up or both down gives 0. If the same two signals fed an OR gate, the light would stay on when both switches were up, which is not how a stair light behaves.
A machine runs only when the guard is closed and the start button is pressed and the stop button is not pressed: `Run = Guard AND Start AND NOT Stop`. A test row with Guard = 1, Start = 1 and Stop = 1 gives 1 AND 1 AND 0 = 0, so the machine stops even with the button held - which is the behaviour a truth table is used to prove.
Flashcards
Click a card to flip it. Mark honestly — the tracker uses this.
Exam-style questions
7 questions, 24 marks. Write your answer and press Mark my answer — it is marked against the scheme and tells you which points you made and what would gain the next mark. You can still reveal the scheme and mark it yourself instead.
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Exam technique for this topic
- Count the inputs and write 2^n rows before you start a truth table: two inputs means four rows, three inputs means eight. A three-input table with four rows loses most of its marks at once.
- Fill the input columns in the fixed order - rightmost alternates every row, the next every two rows, the leftmost every four - so no combination is missed or repeated.
- Put a circle on the output of the gate you mean: NAND is AND with a circle, NOR is OR with a circle. Draw it deliberately, because a missing circle turns one gate into another.
- Bracket every group that feeds one input of another gate. `A AND B OR C` and `A AND (B OR C)` are different circuits, and only the second matches 'A and either B or C'.
- Do not simplify. The syllabus asks for the circuit the statement describes, so a three-gate answer is correct even when a two-gate circuit would give the same output.
Why students lose marks here
Where this fits in O Level Computer Science 2210
This page is one topic of Cambridge O Level Computer Science 2210. O Level Computer Science 2210 is the course home: every area and every topic in Cambridge's own order, the papers you sit and what each one tests, and the exam-practice tools. The full topic list, with each topic linked to its revision page, is on the O Level Computer Science 2210 syllabus page.