Logic gates, diagrams and truth tables

GCSE Computer Science (OCR) · OCR J277 · 2.4.1 · Algorithms and programming (Paper 2) › Boolean logic

42 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 (OCR), marked as you tap.

Revision notes

Logic gates (AND, OR and NOT) combine binary inputs (1 = True, 0 = False) to give an output. You need to draw and read simple logic diagrams, complete truth tables and write logic expressions, for diagrams with up to three inputs. Expect 'complete the truth table', 'write the expression' and 'draw the diagram' questions.

Key facts

  • AND: output 1 only when both inputs are 1 (D-shaped symbol)
  • OR: output 1 when at least one input is 1 (curved back, pointed front)
  • NOT: output is the opposite of the input (triangle with a circle)
  • 1 = True, 0 = False (T/F and other valid notation are accepted)
  • n inputs give 2n rows: 2 inputs = 4 rows, 3 inputs = 8 rows
  • Fill input columns by counting in binary: 000, 001, 010 …
  • Add a column for each gate's output before the final output
  • Brackets show which gate is worked out first

Notes

The three gates

diagram
  • AND (conjunction): the output is 1 only when both inputs are 1. Symbol: a D shape (flat back, rounded front).
  • OR (disjunction): the output is 1 when at least one input is 1. Symbol: a curved back and a pointed front.
  • NOT (negation): one input; the output is the opposite of the input. Symbol: a triangle with a small circle at its tip.
  • Truth tables for the three gates:
    ABA AND BA OR B
    0000
    0101
    1001
    1111
    ANOT A
    01
    10
  • The three symbols:
    ANDORNOT

Truth tables for combined gates

  • A truth table lists every combination of inputs. 2 inputs give 4 rows and 3 inputs give 8 rows (2n rows for n inputs).
  • Fill in the input columns by counting up in binary: 000, 001, 010, 011, 100, 101, 110, 111.
  • Add a column for each gate before the final one, then use those columns to work out the output.
  • Example: P = (A OR B) AND NOT C
    ABCA OR BNOT CP
    000010
    001000
    010111
    011100
    100111
    101100
    110111
    111100

Diagrams and expressions

diagram
  • To write an expression from a diagram, start at the inputs and follow each gate to the output. Put brackets round each gate that feeds into another gate.
  • ABCPA OR BNOT C
    The example P = (A OR B) AND NOT C as a logic diagram
  • To draw a diagram from an expression, draw the gates inside the brackets first, then feed their outputs into the next gate.
  • In a scenario, 'and' usually means AND, 'or' means OR, and 'not' means NOT: for example, a light comes on if it is dark AND someone moves.

How to answer each type of question

Complete a truth table

2 to 4 marksGrade 5
  1. Fill in the input columns in binary order if they are not given.
  2. Work out any middle columns (the inner gates) first.
  3. Then work out the final output for each row.

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

ABA AND BP
00
01
10
11
[4]

Show the model answerHide the model answer
ABA AND BP
0001
0101
1001
1110
1 mark for each correct value of P.

Write the expression for a logic diagram

2 to 3 marksGrade 6
  1. Find the gates that the inputs go into first.
  2. Write each one in brackets, such as (A OR B).
  3. Join them with the gate that produces the output.

Example. In a logic diagram, inputs A and B go into an OR gate. Input C goes into a NOT gate. The outputs of the OR gate and the NOT gate go into an AND gate, whose output is P.
ABCP
Write the logic expression for P. [3]

Show the model answerHide the model answer
P = (A OR B) AND (NOT C)
(A OR B) (1); NOT C (1); the two joined by AND, with correct brackets
(1).

Draw a logic diagram from an expression

3 marksGrade 6
  1. Draw each input on the left.
  2. Draw the gates inside the brackets first.
  3. Feed their outputs into the final gate, and label the output.
  4. Use the correct symbol for every gate.

Example. Draw a logic diagram for P = (NOT A) OR (B AND C). [3]

Show the model answerHide the model answer
Input A goes into a NOT gate (1). Inputs B and C go into an AND gate (1). The outputs of the NOT gate and the AND gate go into an OR gate, whose output is P
(1).
ABCP

Write logic for a scenario

2 to 4 marksGrade 8
  1. Give each input a letter as the question does, with 1 meaning the condition is true.
  2. Turn the words into AND, OR and NOT, keeping the grouping the sentence describes.
  3. Use brackets, and check with one or two rows.

Example. An alarm (P) sounds if the door is open (D = 1) and the system is armed (S = 1), or if the panic button is pressed (B = 1).
(a) Write a logic expression for P. [2]
(b) State the value of P when D = 0, S = 1 and B = 1. [1]

Show the model answerHide the model answer
(a) P = (D AND S) OR B: (D AND S) (1); OR B
(1).
(b) 1 (1), because the panic button is pressed.

Don’t lose marks

  • Drawing the OR symbol when AND is needed, or leaving the circle off a NOT gate.
  • Missing input combinations or repeating a row: 3 inputs need exactly 8 rows.
  • Forgetting brackets, so the order of the gates is unclear.
  • Applying NOT to the wrong part: NOT (A AND B) is different from NOT A AND B.
  • Giving a NOT gate two inputs.

More tips

Memory tricks

  • AND is like two switches in a line (series): both must be on. OR is like two switches side by side (parallel): either one works.
  • AND gives 1 in only one row of a 2-input table; OR gives 0 in only one row.
  • Binary counting order for inputs: the right-hand column alternates 0, 1, 0, 1; the next column pairs 0, 0, 1, 1; and so on.

Exam technique

  • Always fill in any middle columns: they help you and can earn credit.
  • Label every input and the output on diagrams you draw.
  • Check one or two rows of your truth table against the words in the question.

What each grade needs

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

  1. Grade 3
    Recall the truth tables for AND, OR, NOTAND needs both inputs 1; OR needs at least one; NOT reverses the input.
  2. Grade 4
    Recognise the symbols for the three gatesAND is D-shaped, OR has a curved back and a point, NOT is a triangle with a circle.
  3. Grade 5
    Complete a truth table for two gatesAdd a column for the first gate, then work out the final output.
  4. Grade 6
    Write the expression for a logic diagramWork from the inputs to the output, using brackets to show which gate comes first.
  5. Grade 6
    Draw a logic diagram from an expressionDraw the gates in brackets first, then join their outputs to the final gate.
  6. Grade 7
    Complete a three-input truth tableList all 8 input combinations in order and work out each output.
  7. Grade 8
    Turn a written problem into logicWrite an expression and truth table for a scenario, such as an alarm system.

Quick recall

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

State the number of inputs a NOT gate has.
1
A porch light comes on if a movement sensor is triggered or the manual switch is on.
OR
A bathroom extractor fan, F, switches on (F = 1) when the humidity is high (H = 1) or when the light is on (L = 1). Write a Boolean expression for F using H and L.
F = H OR L
A logic OR gate has three inputs, A, B and C. Its truth table has 8 rows. State how many of the 8 rows give an output of 0.
1

Sample questions

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

Question 1Easy3 marks
(a) Which logic gate’s output is 1 only when both of its inputs are 1?
Tick (✓) one box.
[1]
  • OR
  • NOT
  • AND
(b) State the number of inputs a NOT gate has.
[1]
(c) State the output of an AND gate when both of its inputs are 0.
[1]
Show the answer and mark scheme
(a) Answer: AND
(b) Answer: 1
  • 1
(c) Answer: 0
  • 0
Question 2Medium6 marks
An alarm system has three inputs:
  • S = 1 when the system is switched on
  • D = 1 when a door is open
  • B = 1 when the panic button is pressed.
The alarm, A, sounds when the system is switched on and a door is open, or at any time when the panic button is pressed.
(a) Write a Boolean expression for A.
[3]
(b) Draw a logic diagram for the alarm system.
[3]
Show the answer and mark scheme
(a) Answer: A = (S AND D) OR B
  • S AND D
  • OR B
  • brackets / order correct, so that B on its own sounds the alarm: A = (S AND D) OR B
(b)
  • an AND gate with inputs S and D
  • an OR gate with inputs from the AND gate and B
  • the output of the OR gate labelled A (correct symbols used)
Question 3Hard6 marks
Two engineers each design a logic circuit with three inputs, A, B and C, for the same job. They want to know whether their circuits always give the same output.
Discuss how truth tables can be used to decide whether the two circuits always give the same output. Include the strengths and limitations of this method.
[6]
Show the answer and mark scheme
Answer: A full truth table for each circuit (all 8 combinations) is compared row by row. Identical output columns show the circuits are equivalent, and a single difference shows they are not. It is thorough for small circuits but grows too large and error-prone for many inputs.
  • list every possible combination of the inputs (8 rows for 3 inputs)
  • work out the output of each circuit for every row (using working columns)
  • compare the two output columns row by row; if all rows match the circuits are equivalent
  • one row where the outputs differ is enough to show the circuits are not equivalent
  • testing only a few rows could miss a difference, so matching outputs on those rows does not prove equivalence
  • the number of rows doubles with each extra input (for example 10 inputs gives 1024 rows), so the method becomes long and error-prone for large circuits
  • the method is reliable and quick for small circuits such as those with 2 or 3 inputs

Marked with levels of response: the full level descriptors are in the app.

Stuck? Get 1-to-1 help.

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