OCR GCSE COMPUTER SCIENCE · J277 · PAPER 2
Boolean logic
AND, OR and NOT. The tiny yes-or-no decisions inside every processor.
Paper 2 · Lesson 19
OCR GCSE COMPUTER SCIENCE · J277 · PAPER 2
Boolean logic
AND, OR and NOT. The tiny yes-or-no decisions inside every processor.
Paper 2 · Lesson 19
Lesson 19 of the J277 series (Block C, Paper 2, section 2.4 Boolean logic).
Cover hologram from a photo by Bermix Studio / Unsplash.
Device-free: show the slide; pupils write the title and date. Image credit: Bermix Studio / Unsplash (cover hologram)
00 · MISSION · BY THE END OF THIS LESSON
By the end of this lesson you can…
01 Draw the AND, OR and NOT gates and give their truth tables.
02 Read and write Boolean expressions and logic diagrams.
03 Complete a truth table for a circuit with three inputs.
Read the three outcomes. J277 section 2.4 expects pupils to recognise the AND, OR and NOT gate symbols, know their truth tables, combine up to three gates with up to three inputs, and create, complete or edit logic diagrams and truth tables for a given scenario.
Device-free: pupils copy the outcomes and tick each one at the end.
02 · CHECK · DO NOW (LESSON 18)
Warm up: sorting algorithms
1 What happens in one pass of a bubble sort?
2 How do you know a bubble sort has finished?
3 How does an insertion sort place each item?
4 What does a merge sort do first?
▮ TERMINAL // do_now_answers
1 compare each pair of neighbours,
swap if in the wrong order
2 a whole pass with no swaps
3 insert it into the right place
in the sorted part
4 split into single items,
then merge them back in order
Retrieval from lesson 18. Give 4 minutes, then click to reveal the answers line by line.
1 Each pair of neighbouring items is compared and swapped if they are in the wrong order; after one pass the largest item has moved to the end. 2 When a whole pass is made with no swaps, the list is sorted. 3 Each item in turn is taken and inserted into the correct place in the sorted part of the list. 4 The list is split in half again and again until every item is on its own, then the items are merged back together in order.
Device-free: questions on the board; mini whiteboards.
Recap: one bubble sort pass on 5, 1, 4, 2. What is the list now?
1, 2, 4, 5
5, 4, 2, 1
1, 4, 2, 5
1, 5, 4, 2
Answer: C, 1, 4, 2, 5. Trace the pass: compare 5 and 1, swap (1, 5, 4, 2); compare 5 and 4, swap (1, 4, 5, 2); compare 5 and 2, swap (1, 4, 2, 5). The largest item, 5, has bubbled to the end.
Common wrong answers: 1, 2, 4, 5 is the fully sorted list (it needs a second pass); 1, 5, 4, 2 stops after the first comparison.
Device-free: students hold up A, B, C or D cards. Image credit: Jess Bailey / Unsplash
01 · LEARN · MISSION BRIEFING
Think like a processor
Inside every processor, billions of tiny logic gates make decisions with 1s and 0s.
AND
Is everything true?
OR
Is anything true?
NOT
Flip it: true becomes false.
SYSTEM VOICE
System online. Today's mission: think like a processor. Learn the three logic gates, the AND gate, the OR gate and the NOT gate. Complete truth tables, and join gates together to turn a real problem into logic.
Click play for the system voice briefing. The words are also on the slide.
Quick hook: "I will take an umbrella if it is raining AND I am going out." Ask when the umbrella comes along. Then change AND to OR and ask again. Pupils already use these words as logic every day.
Device-free: pupils write AND, OR and NOT with the question beside each.
01 · LEARN · ONLY 1 OR 0
On or off, nothing between
1 A switch is either on or off.
2 In Boolean logic, on is 1 (TRUE) and off is 0 (FALSE).
3 Every input to a logic gate is a 1 or a 0.
4 The gate gives one output, also a 1 or a 0.
Remember: inputs and outputs are only ever 1 or 0.
Click to reveal the steps. The picture is the idea to remember: a switch is an input with exactly two states, on or off. Boolean logic uses the same two values, 1 (TRUE) and 0 (FALSE). Inside a processor, transistors act as billions of tiny switches, and logic gates are built from them.
Ask: is a dimmer switch a Boolean input? (No: it has many levels, not just two.)
Photo: Steve A Johnson / Unsplash.
Device-free: pupils flick the classroom light switch in their heads: up = 1, down = 0. Image credit: Steve A Johnson / Unsplash
01 · LEARN · GATE SYMBOLS
Three logic gates
AND
P is 1 only if A and B are both 1.
OR
P is 1 if A or B (or both) is 1.
NOT
One input. P is the opposite of A.
These are the gate symbols OCR uses. Help pupils tell them apart: AND has a flat back and a round front, like a D. OR has a curved back and a pointed tip, like a shield. NOT is a triangle with a small circle on its output; the circle means "invert".
AND and OR take two inputs (A and B); NOT takes only one. Each gives one output, P. Inputs come in on the left, the output leaves on the right.
Device-free: pupils draw the three symbols three times each, labelling A, B and P.
01 · LEARN · TRUTH TABLES
Every input, every output
▮ TERMINAL // and.tt
A | B | P
---+---+---
0 | 0 | 0
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1
▮ TERMINAL // or.tt
A | B | P
---+---+---
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 1
▮ TERMINAL // not.tt
A | P
---+---
0 | 1
1 | 0
Rows: 2 inputs give 4 rows (00, 01, 10, 11). 3 inputs give 8 rows, 000 to 111. Always count up in binary.
A truth table lists every possible combination of inputs and the output for each. Click to reveal each table row by row, asking pupils to predict P before each click.
AND: P is 1 only in the last row (1, 1). OR: P is 0 only in the first row (0, 0). NOT: the output is the opposite of the input.
Writing the inputs in binary counting order (00, 01, 10, 11) makes sure no combination is missed. With n inputs there are 2 to the power n rows: 2 inputs, 4 rows; 3 inputs, 8 rows.
Device-free: pupils copy all three tables, covering the P column and predicting first.
01 · LEARN · LOGIC DIAGRAMS
Join the gates together
1 A and B go into an AND gate.
2 C goes into a NOT gate.
3 Both results go into an OR gate.
4 The output of the OR gate is P.
Brackets show what is worked out first.
A Boolean expression and a logic diagram show the same thing. Read the expression P = (A AND B) OR NOT C from the inside out: the bracket (A AND B) is one gate, NOT C is a second gate, and OR joins their two results into the output P.
Click to reveal each step while pointing to the matching part of the diagram. Going the other way, from a diagram to an expression, work from the inputs towards the output and write down each gate as you meet it.
Device-free: pupils copy the diagram and label the wire coming out of each gate (A AND B, NOT C).
01 · LEARN · THREE INPUTS
P = (A AND B) OR NOT C
▮ TERMINAL // truth_table_3_inputs
A | B | C | A AND B | NOT C | P
---+---+---+---------+-------+---
0 | 0 | 0 | 0 | 1 | 1
0 | 0 | 1 | 0 | 0 | 0
0 | 1 | 0 | 0 | 1 | 1
0 | 1 | 1 | 0 | 0 | 0
1 | 0 | 0 | 0 | 1 | 1
1 | 0 | 1 | 0 | 0 | 0
1 | 1 | 0 | 1 | 1 | 1
1 | 1 | 1 | 1 | 0 | 1
1 3 inputs, so 8 rows: 000 to 111.
2 Work out A AND B for each row.
3 Work out NOT C for each row.
4 OR the two columns: P is 1 if either is 1.
Click to reveal the truth table one row at a time. Ask pupils to work out each row on mini whiteboards before the click.
Working: A AND B is 1 only when A = 1 and B = 1 (the last two rows). NOT C is 1 whenever C = 0 (rows 1, 3, 5 and 7). P = 1 if either column is 1, so P = 1, 0, 1, 0, 1, 0, 1, 1 from top to bottom.
Extra columns for each gate are not required by the exam, but they make mistakes much less likely and examiners accept them.
Device-free: pupils copy the table with the P column blank and fill it in before the reveal.
01 · LEARN · SCENARIOS
From words to logic
1 Find the output: what happens?
2 Find the inputs: the conditions. Give each a letter.
3 Swap the joining words for AND, OR and NOT.
4 Add brackets to show what is worked out first.
▮ TERMINAL // automatic_door
The door opens if a person is seen
OR the staff button is pressed,
AND the door is NOT locked.
A = a person is seen
B = the staff button is pressed
C = the door is locked
P = the door opens
> P = (A OR B) AND NOT C_
Talk through the four steps, then click to reveal the scenario and the working.
The output is the door opening (P). The inputs are the conditions: a person is seen (A), the staff button is pressed (B), the door is locked (C). "Or" becomes OR, "and" becomes AND, "not locked" becomes NOT C. The brackets around A OR B matter: the door must check "someone wants it open" first, then that it is not locked.
Check one row: A = 1, B = 0, C = 1. A OR B = 1, NOT C = 0, so P = 0: the door stays shut because it is locked. Good.
Device-free: pupils draw the logic diagram for P = (A OR B) AND NOT C.
01 · LEARN · SUMMARY
Know your gates
AND
Flat back, round front, like a D.
1 only if both inputs are 1.
OR
Curved back, pointed tip.
1 if at least one input is 1.
NOT
Triangle with a small circle.
One input, flipped: 1 becomes 0.
SYSTEM VOICE · KEY DEFINITION
A logic gate takes one or two inputs, each a 1 or a 0, and gives a single output. A truth table shows the output for every possible combination of inputs.
Summary of the three gates: the shape to draw and the rule to remember. Examiners often lose marks for gates drawn so loosely that AND and OR cannot be told apart, so insist on the flat back for AND and the curved back for OR.
Play the key definition. Device-free: pupils close their books and draw all three gates with their truth tables from memory, then check.
AND, OR or NOT?
AND
OR
NOT
Turns a 1 into 0 and a 0 into 1
Heater on when the room is not warm
Output 1 only when both inputs are 1
Bell rings if the front or back button is pressed
Car starts only with the key in and the brake on
Output 1 when at least one input is 1
Answers. AND: output 1 only when both inputs are 1; car starts only with the key in and the brake on. OR: output 1 when at least one input is 1; bell rings if the front or back button is pressed. NOT: turns a 1 into 0 and a 0 into 1; heater on when the room is not warm.
Ask: would the bell still ring if both buttons were pressed at once? (Yes: OR includes the case where both are 1.)
Device-free: pupils draw three columns and write each statement in the right one.
P = (A AND B) OR C. Which inputs make P = 0?
A = 1, B = 0, C = 0
A = 1, B = 1, C = 0
A = 0, B = 0, C = 1
A = 1, B = 1, C = 1
Answer: A. With A = 1, B = 0, C = 0: A AND B = 0, and C = 0, so 0 OR 0 = 0.
B: A AND B = 1, so P = 1. C: C = 1, so P = 1. D: both parts are 1, so P = 1. P is only 0 when both A AND B and C are 0.
Device-free: students hold up A, B, C or D cards. Image credit: Umberto / Unsplash
A car alarm sounds (P) when it is set AND a door is opened. Which expression fits?
P = Set OR Door
P = NOT Set AND Door
P = Set AND NOT Door
P = Set AND Door
Answer: D, P = Set AND Door. Both conditions must be true, so it is an AND with no NOT.
A (OR) would set off the alarm whenever a door opens, even with the alarm switched off. B sounds only when the alarm is NOT set. C sounds when the alarm is set and the door is NOT opened.
Device-free: students hold up A, B, C or D cards. Image credit: Bence Balla-Schottner / Unsplash
03 · DEBUG · SPOT THE MISTAKE
One row of Amara's OR table is wrong
▮ TERMINAL // amara_or_table.txt
A | B | A OR B
---+---+--------
row 1 0 | 0 | 0
row 2 0 | 1 | 1
row 3 1 | 0 | 1
row 4 1 | 1 | 0
Check each row against the OR rule. Then tap the marker.
Tip: in Boolean logic, OR includes "both". Everyday "or" often does not.
Give a minute to find the mistake before tapping the marker.
Answer: row 4. Amara has used the everyday meaning of "or" (one or the other, not both). In Boolean logic, A OR B is 1 when A is 1, when B is 1, or when both are 1. Only row 1 (0, 0) gives 0. Rows 1, 2 and 3 are correct.
Device-free: copy the table onto the board; pupils write the wrong row number and the correct value.
Put the steps for completing a truth table in order.
Correct order: 1 count the inputs (3 inputs give 8 rows); 2 list the inputs in binary order, 000 to 111; 3 add a column for each gate; 4 fill in the first gate's column; 5 fill in the next gate's column; 6 work out the final output P.
Ask: why count in binary? (So that no combination is missed or repeated.)
Device-free: pupils write the six steps on sticky notes and order them on the desk.
Complete the summary.
An AND gate outputs 1 only when both inputs are 1. An OR gate outputs 1 when at least one input is 1. A NOT gate has one input and flips it. A truth table for three inputs has 8 rows.
Answers in order: AND, OR, NOT, flips, 8. Distractors: 4 (the number of rows for two inputs), adds, doubles.
Device-free: paragraph on the board with gaps and the word bank; pupils write the five missing words.
EXAM · A car alarm sounds (P = 1) when it is set (S) AND the door (D) OR the window (W) sensor is triggered. Write a Boolean expression for P and draw the logic diagram. [4 marks]
Exam-style question, 4 marks. Give 6 minutes. The model answer is on the next slide.
Mark scheme: 1 mark for the expression P = S AND (D OR W), with brackets; 1 mark for D and W going into an OR gate; 1 mark for the OR output and S going into an AND gate; 1 mark for correct gate symbols with inputs and output labelled.
Accept (D OR W) AND S. Do not award the expression mark for S AND D OR W without brackets, as it is unclear which gate comes first.
Device-free: pupils answer on paper, then peer-mark with the next slide.
04 · EXAM · MODEL ANSWER
Expression first, then gates
▮ TERMINAL // car_alarm
> P = S AND (D OR W)
1 D and W into an OR gate
2 OR output and S into an AND gate
MARK SCHEME
1 mark: expression with brackets
1 mark: D and W into an OR gate
1 mark: OR output and S into AND
1 mark: correct symbols and labels
Check: S = 1, D = 0, W = 1 gives D OR W = 1, so P = 1.
Click to reveal the model answer step by step.
The words "the door OR the window" are grouped together, so they go in brackets and into one OR gate. The alarm must also be set, so the result of that OR gate goes into an AND gate with S.
Common mistakes: no brackets (S AND D OR W), drawing an AND gate that looks like an OR gate, and forgetting to label the inputs and the output.
Device-free: pupils check their own answer against the four marks and correct it in a different colour.
How sure are you about logic gates?
Very: I can do 3-input tables
Fairly: the diagrams are tricky
Not yet: I need another go
Anonymous exit poll. If many pupils find diagrams tricky, start the next lesson with two quick expressions to draw on mini whiteboards.
Device-free: thumbs up, sideways or down.
05 · NEXT · KEEP GOING
Keep going
Isaac Computer Science
Free online lessons and questions. Look for the Boolean logic topic.
BBC Bitesize
GCSE Computer Science, OCR: revise Boolean logic and truth tables.
Logic at home
Write a rule such as "I go out if it is NOT raining AND my homework is done". Draw it and fill in its truth table.
Next lesson: robust programs, defensive design and testing.
Point pupils to the places to practise. Isaac Computer Science and BBC Bitesize are free.
Logic at home: "I go out if it is NOT raining AND my homework is done" is P = NOT R AND H. Its truth table has 2 inputs, so 4 rows, and P = 1 only when R = 0 and H = 1.
Device-free: pupils bring their own rule, diagram and truth table to the next lesson.