A-Level Computer Science / Unit 3: Hardware, Memory and Control

3.2.1 Logic Gates and Truth Tables

πŸ”’ Lesson slides are available to signed-in users. Sign in

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.
Language supportoutput = resultinvert = change 0 to 1 or 1 to 0combination = a possible group of input values

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.

Truth table: a table showing the output for every possible input combination.

We use letters such as A and B for inputs. We use X for the final output.

AS exam requirement: NOT has one input. Each of the other five gates has two inputs. A complete circuit can have more than two inputs by connecting gates.

2. Learn the six gates

Read each sentence carefully. The words both, at least one, and different have different meanings.

GateWhen is X = 1?Expression
NOTWhen A is 0. This gate reverses A.X = NOT A
ANDWhen A and B are both 1.X = A AND B
ORWhen at least one input is 1. Both may be 1.X = A OR B
NANDWhen A and B are not both 1.X = A NAND B
NORWhen A and B are both 0.X = A NOR B
XORWhen 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 inputsNumber of rowsReason
120, 1
2400, 01, 10, 11
38From 000 to 111
416All four-digit binary combinations

Example: NAND

First find A AND B. Then invert that result.

ABA AND BX = A NAND B
0001
0101
1001
1110

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.

A and BEnter NAND
P = A NAND BIntermediate output
X = P AND CFinal output

Intermediate output means a result in the middle of the circuit. Write it in a new truth-table column.

ABCP = A NAND BX = P AND C
00010
00111
01010
01111
10010
10111
11000
11100
Useful check: if C = 0, the final AND gate must give X = 0. You can use this to check four rows quickly.

5. Interactive: Gate and Circuit Lab

Try before you reveal. Change the inputs, predict the output, and use the explanation to check your thinking.

Gate and Circuit Lab

Choose β†’ Predict β†’ Check β†’ Explain

2 learning modes

Predict the output for the selected inputs.

ABX

The highlighted row matches your inputs. β€œ?” means that you have not revealed the result yet.

Score: 0 / 0

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.

Exam habit: Write input combinations in a consistent order. Add a new column for each gate before calculating the final output.