AS Computer Science
Logic Gates and Truth Tables
Computers use circuits to make simple decisions. A logic gate takes a signal of 0 or 1 and produces a result of 0 or 1. We can join gates to make a larger circuit.
By the end, I canβ¦
- recognise all six required logic gates;
- explain when each gate gives an output of 1;
- make a truth table for a gate or a multi-stage circuit;
- use intermediate outputs to show my working.
1. Three ideas before you start
Binary values
1 means TRUE (or ON). 0 means FALSE (or OFF).
Logic gate
A small electronic circuit that follows one logic rule.
Logic circuit
One or more gates connected to produce an output. In a multi-stage circuit, the result of one gate can enter another gate.
We use letters such as A and B for inputs. We use X for the final output.
2. Learn the six gates
Read each sentence carefully. The words both, at least one, and different have different meanings.
| Gate | When is X = 1? | Expression |
|---|---|---|
| NOT | When A is 0. This gate reverses A. | X = NOT A |
| AND | When A and B are both 1. | X = A AND B |
| OR | When at least one input is 1. Both may be 1. | X = A OR B |
| NAND | When A and B are not both 1. | X = A NAND B |
| NOR | When A and B are both 0. | X = A NOR B |
| XOR | When the two inputs are different. | X = A XOR B |
Common mistake: OR and XOR
If A = 1 and B = 1, OR gives 1, but XOR gives 0. The word βexclusiveβ in XOR means one or the other, but not both.
In circuit symbols, a small circle at the output means the output is inverted. NAND is an AND shape with a circle. NOR is an OR shape with a circle. XOR is an OR shape with an extra curved line. You can explore the symbols in the lab below.
3. Write a complete truth table
A truth table needs one row for every combination. The number of rows is 2number of inputs.
| Number of inputs | Number of rows | Reason |
|---|---|---|
| 1 | 2 | 0, 1 |
| 2 | 4 | 00, 01, 10, 11 |
| 3 | 8 | From 000 to 111 |
| 4 | 16 | All four-digit binary combinations |
Example: NAND
First find A AND B. Then invert that result.
| A | B | A AND B | X = A NAND B |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
The order of the rows helps you check that you have not missed a combination.
4. Work through a circuit in stages
Consider the expression X = (A NAND B) AND C. It has three input variables, but every gate still uses at most two inputs.
Intermediate output means a result in the middle of the circuit. Write it in a new truth-table column.
| A | B | C | P = A NAND B | X = P AND C |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 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 |
5. Interactive: Gate and Circuit Lab
Try before you reveal. Change the inputs, predict the output, and use the explanation to check your thinking.
This interactive model shows the logic rules; the diagram is for learning and is not a wiring plan for a physical circuit.
6. Original exam-style practice
Work on paper first. Then open the answers to self-check.
Question A Β· Recall [2]
Give the output of an XOR gate for input pairs 00, 01, 10 and 11, in this order.
Show suggested answer
0, 1, 1, 0. XOR gives 1 when the inputs are different.
Question B Β· Explain [2]
Why is NAND different from AND?
Show suggested answer
NAND produces the inverse of AND [1]. When both inputs are 1, AND gives 1 but NAND gives 0 [1].
Question C Β· Apply [4]
A circuit has the expression X = (A XOR B) NAND C. Find X for the input combinations 000, 011, 101, 110. Show the XOR result before the NAND result.
Show suggested answer
000 β 1 (XOR=0); 011 β 0 (XOR=1); 101 β 0 (XOR=1); 110 β 1 (XOR=0). NAND is 0 only if both its inputs are 1. One mark per correct X.