Truth tables and logic

GCSE Computer Science (Edexcel) · Edexcel 1CP2 · 1.3 · Computational thinking

33 exam-style questions plus unlimited generated ones on this topic, at up to four difficulty levels, with full mark schemes. Notes and past-paper booklets are open to everyone. Practice needs a free account.

Or take a quick quiz: 10 questions on this subtopic in GCSE Computer Science (Edexcel), marked as you tap.

Revision notes

The logical operators AND, OR and NOT combine True/False (1/0) values. You need to complete truth tables with up to three inputs and use logic to solve problems, such as writing a logic statement for a control system. Truth table questions are usually worth 2 to 4 marks.

Key facts

  • 1 = True, 0 = False
  • AND: 1 only if both inputs are 1
  • OR: 1 if at least one input is 1
  • NOT: reverses the input (NOT 1 = 0, NOT 0 = 1)
  • Rows = 2inputs: 2 inputs → 4 rows, 3 inputs → 8 rows
  • Three-input columns: A 00001111, B 00110011, C 01010101
  • Order: brackets, NOT, AND, OR
  • Python: and, or, not

Notes

The three logical operators

diagram
  • 1 means True (on, yes) and 0 means False (off, no).
  • AND: the output is 1 only if both inputs are 1.
  • OR: the output is 1 if at least one input is 1.
  • NOT: has one input, and the output is the opposite: NOT 1 = 0 and NOT 0 = 1.
    ABA AND BA OR B
    0000
    0101
    1001
    1111
  • ABABAA AND BA OR BNOT A
    The three operators drawn as logic gates: AND (D shape), OR (curved) and NOT (triangle with a circle)
  • Order: brackets first, then NOT, then AND, then OR.

Building a truth table

  • Number of rows = 2number of inputs: 2 inputs give 4 rows and 3 inputs give 8 rows.
  • List the inputs in binary counting order, 000 to 111. With three inputs, column A goes 0000 1111, B goes 0011 0011 and C goes 0101 0101.
  • Add a working column for each part of the statement, then the output column. For P = (A AND B) OR NOT C:
    ABCA AND BNOT CP
    000011
    001000
    010011
    011000
    100011
    101000
    110111
    111101
  • P is 1 in every row where at least one of the two working columns is 1.

Solving problems with logic

diagram
  • Give each condition a letter, then join them with AND, OR and NOT, using brackets to show which parts go together.
  • Example: an alarm (S) sounds if a door is opened (D) while the system is set (T), or if the panic button (P) is pressed: S = (D AND T) OR P.
  • DTPSD AND TS = (D AND T) OR P
    The brackets show which part is worked out first: D AND T, then OR P
  • Words to look for: 'both' means AND; 'either' or 'at least one' means OR; 'not' means NOT; 'but not' means AND NOT.
  • In Python the operators are and, or and not, used with True and False, e.g. if (door and alarmSet) or panic:.
  • Edexcel questions write logic statements in words, using AND, OR and NOT with brackets, e.g. P = A AND NOT B. Work through a long statement one part at a time, just like the working columns.

How to answer each type of question

Complete a truth table

2 to 4 marksGrade 5
  1. Check that the input columns are in binary counting order.
  2. Add a working column for the part in brackets.
  3. Work out the output row by row from the working column and the other input.

Example. Complete the truth table for X = A AND (B OR C).

ABCB OR CX
000
001
010
011
100
101
110
111

Show the model answerHide the model answer
ABCB OR CX
00000
00110
01010
01110
10000
10111
11011
11111
1 mark for each correct pair of rows in the X column (rows 1⁠–⁠2, 3⁠–⁠4, 5⁠–⁠6, 7⁠–⁠8), 4 marks in total. X is 1 only in the last three rows.

Complete a truth table with NOT outside brackets

3 to 4 marksGrade 6
  1. Work out the part inside the brackets first, in its own column.
  2. Reverse that whole column for the NOT.
  3. Then combine it with the remaining input.

Example. Complete the truth table for P = NOT (A AND B) AND C.

ABCA AND BNOT (A AND B)P
000
001
010
011
100
101
110
111

Show the model answerHide the model answer
ABCA AND BNOT (A AND B)P
000010
001011
010010
011011
100010
101011
110100
111100
A AND B column (1); NOT (A AND B) column (1); P column (1).

Write a logic statement for a situation

2 to 3 marksGrade 7
  1. Match each condition in the description to its input letter.
  2. Decide which conditions must all be true (AND), which are alternatives (OR) and which must be false (NOT).
  3. Add brackets so that the statement groups the conditions as described.

Example. A greenhouse fan (F) is controlled by three inputs:
T is 1 when the temperature is above 30 °C
W is 1 when the window is open
M is 1 when the manual switch is on.
The fan is on when the temperature is above 30 °C and the window is not open, or when the manual switch is on.
Write a logic statement for F.

Show the model answerHide the model answer
F = (T AND NOT W) OR M
T AND NOT W (1); OR M, with brackets so that M on its own turns the fan on
(1).

Use a truth table to solve a problem

1 to 2 marksGrade 8
  1. Complete (or read) the truth table for the statement.
  2. Find the rows where the output has the value you want.
  3. Give the inputs for those rows, and explain what they mean if asked.

Example. Use the statement F = (T AND NOT W) OR M for the greenhouse fan.
(a) State the number of rows in a truth table for F.
(b) The manual switch is off (M = 0). State the values of T and W that turn the fan on.

Show the model answerHide the model answer
(a) 8 (1): three inputs, and 2 × 2 × 2 = 8
(b) T = 1 and W = 0 (1): the temperature is above 30 °C and the window is closed.

Don’t lose marks

  • Missing out or repeating a combination of inputs, so the table has the wrong rows.
  • Applying NOT to the whole statement when it only applies to one input, or the other way round.
  • Working out OR before AND when there are no brackets.
  • Skipping the working columns and then making slips in the output column.
  • Mixing 1/0 with True/False in the same table. Use the form the table already uses.

More tips

Memory tricks

  • AND = all, OR = any, NOT = opposite.
  • Input patterns halve each column: runs of four, then two, then one.
  • Quick check: an AND column usually has few 1s; an OR column has few 0s.
  • Don't share a NOT across brackets: NOT (A AND B) is not the same as NOT A AND NOT B. Work out the bracket, then reverse it.

Exam technique

  • Add working columns even if the table in the question doesn't have them; you can write them next to it.
  • Keep the input rows in the order the question gives. Don't reorder them.
  • Read descriptions carefully for 'both', 'either', 'not' and 'but not' (AND NOT) before you write a statement.

What each grade needs

What you need to be able to do, from the first marks up to the top grade.

  1. Grade 3
    State the outputs of AND, OR and NOTAND needs both inputs to be 1; OR needs at least one; NOT reverses its input.
  2. Grade 4
    Complete a truth table with two inputsFour rows: 00, 01, 10, 11.
  3. Grade 5
    Complete a truth table with three inputsEight rows, listed in binary counting order from 000 to 111.
  4. Grade 6
    Use working columns for brackets and NOTWork out each part of the statement in its own column before the output.
  5. Grade 7
    Write a logic statement from a descriptionTurn a rule such as 'on if A and not B, or if C' into a statement.
  6. Grade 8
    Use a truth table to solve a problemFind the input combinations that give a required output.

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

Logic statements use the operators AND, OR and NOT. Each input and each output is either 0 (False) or 1 (True). State the output of NOT when its input is 1.
0
State the Python logical operator that gives True only when both of the conditions it joins are True.
and
A car has a warning light, W. The light comes on when the fuel is low (F = 1) or when the tyre pressure is low (T = 1). Write a logic statement for W.
W = F OR T
Complete the sentence: the output of the ______ operator is 1 only when both of its inputs are 1.
AND
Write the letters A, B and C in the order the student should do the steps.
B, C, A

Sample questions

Written for this site in the style of Edexcel exam questions. They are not taken from real past papers.

Question 1Easy1 mark
A logic statement is Q = A OR B.
Which pair of inputs gives an output of 0? Tick (✓) one box.
[1]
  • A = 1, B = 0
  • A = 0, B = 1
  • A = 0, B = 0
  • A = 1, B = 1
Show the answer and mark scheme
Answer: A = 0, B = 0
Question 2Medium7 marks
A greenhouse has a fan, F, that is controlled by three inputs:
T = 1 when the temperature is above 30 °C
W = 1 when a window is open
H = 1 when the humidity is high
The fan switches on (F = 1) when the temperature is above 30 °C and the window is not open, or when the humidity is high.
(a) Write a logic statement for F.
[2]
(b) Complete the truth table in Table 1 for F.
[4]
Table 1
TWHF
000
001
010
011
100
101
110
111
(c) The temperature is above 30 °C but the fan is off. State the values of W and H.
[1]
Show the answer and mark scheme
(a) Answer: F = (T AND NOT W) OR H
  • T AND NOT W
  • combined with H using OR so that H = 1 on its own switches the fan on: F = (T AND NOT W) OR H
(b) Answer:
T | W | H | F
--+---+---+--
0 | 0 | 0 | 0
0 | 0 | 1 | 1
0 | 1 | 0 | 0
0 | 1 | 1 | 1
1 | 0 | 0 | 1
1 | 0 | 1 | 1
1 | 1 | 0 | 0
1 | 1 | 1 | 1
  • F column, rows 1–2: 0, 1
  • F column, rows 3–4: 0, 1
  • F column, rows 5–6: 1, 1
  • F column, rows 7–8: 0, 1
(c) Answer: W = 1 and H = 0 (the window is open and the humidity is not high)
  • W = 1 and H = 0
Question 3Hard8 marks
A theme park ride uses three Boolean variables:
rideOpen – True when the ride is open
tallEnough – True when the rider is at least 120 cm tall
withAdult – True when the rider is with an adult
A rider may board only if the ride is open and the rider is either tall enough or with an adult (or both).
(a) Write a Python if statement that outputs Board when a rider may board.
[2]
(b) A programmer writes the condition as rideOpen and tallEnough or withAdult instead.
Complete the truth table in Table 2. R, T and W stand for rideOpen, tallEnough and withAdult. Column X is the correct condition, R AND (T OR W). Column Y is the programmer’s condition.
[4]
Table 2
RTWXY
000
001
010
011
100
101
110
111
(c) Use your truth table to explain the problem with the programmer’s condition.
[2]
Show the answer and mark scheme
(a) Answer:
if rideOpen and (tallEnough or withAdult):
    print("Board")
  • rideOpen and …
  • (tallEnough or withAdult) in brackets, with print("Board") inside the if statement
(b) Answer:
R | T | W | X | Y
--+---+---+---+--
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 | 1 | 1
1 | 1 | 0 | 1 | 1
1 | 1 | 1 | 1 | 1
  • X column, rows 1–4: 0, 0, 0, 0
  • X column, rows 5–8: 0, 1, 1, 1
  • Y column, rows 1–4: 0, 1, 0, 1
  • Y column, rows 5–8: 0, 1, 1, 1
(c) Answer: X and Y differ when the ride is closed and the rider is with an adult (rows 2 and 4). Because and is evaluated before or, withAdult being True makes the programmer’s condition True on its own, so a rider with an adult could board a closed ride.
  • the two columns differ when R = 0 and W = 1 / when the ride is closed and the rider is with an adult
  • because and is evaluated before or, withAdult on its own makes the condition True / a rider with an adult could board when the ride is closed

More in Computational thinking

Stuck? Get 1-to-1 help.

Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.