Topic 10 · Boolean logic

Logic gates and truth tables

Video lesson: Logic gates and truth tables▶ Watch the video lessonShort, exam-focused explanation of this topic on the CS with Aamir YouTube channel.

A logic gate is an electronic component that takes one or more binary inputs (0 or 1) and produces a single binary output. Computers are built from millions of these gates. You need to know six gates, their truth tables, and how to work out the output of a circuit made from several gates.

The six logic gates

GateOutput is 1 when…Boolean expression
NOTthe input is 0 (it inverts the input)X = NOT A
ANDboth inputs are 1X = A AND B
ORat least one input is 1X = A OR B
NANDNOT both inputs are 1 (opposite of AND)X = A NAND B
NORboth inputs are 0 (opposite of OR)X = A NOR B
XORthe inputs are differentX = A XOR B

Truth table for the two-input gates

ABANDORNANDNORXOR
0000110
0101101
1001101
1111000

A quick way to remember: NAND and NOR are simply AND and OR with the output inverted, and XOR is like OR except that 1 and 1 gives 0.

How many rows does a truth table need?

A truth table needs 2n rows, where n is the number of inputs: 2 inputs → 4 rows, 3 inputs → 8 rows. List the inputs in binary counting order (000, 001, 010 … 111) so that you don't miss a combination.

Worked example: a logic circuit

Complete the truth table for X = (A AND B) OR (NOT C). Work it out in stages by adding a column for each gate:

ABCA AND BNOT CX
000011
001000
010011
011000
100011
101000
110111
111101

From a problem statement to a circuit

Exam questions often describe a real situation, for example: "An alarm (X) sounds if the door is open (A = 1) AND the system is switched on (B = 1), OR if the panic button is pressed (C = 1)." Turn each condition into part of an expression – here X = (A AND B) OR C – then draw one gate for each operator.

Exam tips

Want the full topic notes, slides and worksheets? See Notes & Slides, practise with the free CS with Aamir Quiz App, or order the O Level Computer Science Study Guide.