Boolean Logic - Worksheets, Questions and Revision

20 original exam-style questions - 12 pages of questions with a full mark scheme - free printable PDF.

Download PDFJump to mark scheme (page 13)Read the revision guide
« Previous: Producing Robust ProgramsNext: Data Representation: Number Systems »
Revision Library
revisionlibrary.co.uk
GCSE · OCR

P2.4 Boolean Logic

OCR J277 · Calculators not allowed · about 100 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
In computer science, a Boolean is a data type that can only take one of two values.
(a)State the two values that a variable of Boolean data type can hold.(1)
(b)Give an example of a real-world question, other than a question about an alarm system, that has a Boolean (yes/no) answer.(1)
(Total for Question 1 is 2 marks)
2
The NOT operator inverts (reverses) the value of a single Boolean input A. Complete the truth table below for NOT A.
ANOT A
0
1
(Total for Question 2 is 2 marks)
3
The AND and OR operators combine two Boolean inputs, A and B, to produce a single output.
(a)Complete the truth table for the AND operator.
ABA AND B
00
01
10
11
(4)
(b)Complete the truth table for the OR operator.
ABA OR B
00
01
10
11
(4)
(Total for Question 3 is 8 marks)
4
A student sets A = 1 and B = 0.
(a)What is the value of A AND B?(1)
  • A) 0
  • B) 1
  • C) Cannot be determined
  • D) Both 0 and 1
(b)What is the value of A OR B?(1)
  • A) 0
  • B) 1
  • C) Cannot be determined
  • D) Both 0 and 1
(Total for Question 4 is 2 marks)
5
A house alarm system has two sensors: a door sensor D and a window sensor W. Each sensor outputs 1 if triggered and 0 if not triggered. Let A represent whether the alarm sounds (1 = sounds, 0 = silent).
(a)The alarm should sound if either sensor is triggered. Write a Boolean expression for A in terms of D and W.(1)
(b)The owner finds the alarm sounds too often because of a cat setting off one sensor. Write a new Boolean expression for A so that both sensors must be triggered at the same time before the alarm sounds.(1)
(Total for Question 5 is 2 marks)
6
Consider the Boolean expression X = NOT A AND B, where A and B are single-bit inputs.
(a)Complete the truth table for X.
ABNOT AX
00
01
10
11
(4)
(b)State how many of the four input combinations of A and B give an output of X = 1.(1)
(Total for Question 6 is 5 marks)
7
A smart heating system has a temperature sensor that outputs tempLow = True when the room temperature is below 18C, a window sensor windowClosed = True when the window is shut, and a manual override switch override, which the user can set to True to force the heating on regardless of the other sensors.
(a)Write a Boolean expression for heatingOn that turns the heating on when the temperature is low AND the window is closed, or when the override switch is on.(2)
(b)State the value of heatingOn when tempLow = True, windowClosed = False and override = False.(1)
(Total for Question 7 is 3 marks)
8
A logic circuit has two inputs, P and Q. Input P is connected to the input of a NOT gate. The output of the NOT gate, together with input Q, are the two inputs to an AND gate. The output of the AND gate is X.
(a)Write the Boolean expression for X in terms of P and Q.(1)
(b)Complete the truth table for the circuit.
PQX
00
01
10
11
(4)
(c)State the input values of P and Q that produce X = 1.(1)
(Total for Question 8 is 6 marks)
9
A programmer wants to build a logic circuit that produces the output of the Boolean expression X = A OR NOT B, using two inputs A and B.
(a)State the two logic gates that are needed to build this circuit.(2)
(b)Describe how the two gates would be connected to produce the correct output X.(2)
(Total for Question 9 is 4 marks)
10
Complete the truth table below for the expression Output = A AND (B OR C).
ABCB OR COutput
000
001
010
011
100
101
110
111
(Total for Question 10 is 4 marks)
11
A program is written using OCR Exam Reference Language:
age <- 16
hasID <- True
IF age >= 18 OR hasID == True THEN
    OUTPUT "Entry allowed"
ELSE
    OUTPUT "Entry denied"
ENDIF
(a)State the output produced when this code is run with the values shown above.(1)
(b)The line hasID <- True is changed to hasID <- False, with age still equal to 16. State the new output.(1)
(c)Complete a trace table showing the values of age, hasID and the OUTPUT produced for both runs described in parts (a) and (b).
RunagehasIDOUTPUT
1
2
(3)
(Total for Question 11 is 5 marks)
12
A login validation routine uses three variables: usernameLength (an integer), hasDigit (a Boolean, True if the password contains at least one digit) and hasSpecialChar (a Boolean, True if the password contains at least one special character such as ! or #). Using OCR Exam Reference Language, write an IF statement that outputs "Valid" if usernameLength is at least 8 AND both hasDigit and hasSpecialChar are True, and otherwise outputs "Invalid".
(Total for Question 12 is 4 marks)
13
A student claims that NOT (A AND B) always produces the same output as (NOT A) OR (NOT B) for every combination of A and B.
(a)Complete the two truth tables below to test this claim.
ABA AND BNOT (A AND B)
00
01
10
11
ABNOT ANOT B(NOT A) OR (NOT B)
00
01
10
11
(4)
(b)State whether the student's claim is correct, using evidence from your completed tables.(1)
(Total for Question 13 is 5 marks)
14
Complete the truth table below for the expression Output = (A OR B) AND NOT C.
ABCA OR BNOT COutput
000
001
010
011
100
101
110
111
(Total for Question 14 is 4 marks)
15
A programmer is designing a form-validation routine for a website that collects a user's age (which must be an integer between 5 and 100 inclusive) and a consent Boolean (True if the user has ticked a consent box).

Explain how Boolean logic operators (AND, OR, NOT) could be used to validate this data, including at least one example of a condition that combines more than one operator.
(Total for Question 15 is 4 marks)
16
A program is written using OCR Exam Reference Language:
count <- 0
total <- 0
FOR i <- 1 TO 5
    INPUT mark
    IF mark >= 40 AND mark <= 100 THEN
        total <- total + mark
        count <- count + 1
    ENDIF
NEXT i
IF count > 0 THEN
    average <- total / count
    OUTPUT average
ELSE
    OUTPUT "No valid marks"
ENDIF

The program is run with the five inputs, in order: 35, 72, 100, 45, 105.
(a)Complete a trace table for this program using the five inputs given.
imarkcondition true?totalcount
135
272
3100
445
5105
(5)
(b)State the value output by the program.(1)
(Total for Question 16 is 6 marks)
17
A vending machine dispenses an item if a coin has been inserted (coinInserted) and the selected item is in stock (stockAvailable), or if an engineer's override switch (overrideSwitch) is on, which bypasses the coin and stock requirements.
(a)Write a Boolean expression for dispense in terms of coinInserted, stockAvailable and overrideSwitch.(2)
(b)The engineer adds a safety interlock: a doorOpen sensor must be False before the machine is allowed to dispense anything, even when the override switch is on. Rewrite the expression for dispense to include this new rule.(2)
(Total for Question 17 is 4 marks)
18
The truth table below shows the output of a Boolean expression using three inputs A, B and C.
ABCOutput
0000
0010
0100
0111
1000
1011
1101
1111
(a)Which expression produces this truth table?(1)
  • A) (A AND B) OR (B AND C) OR (A AND C)
  • B) A AND B AND C
  • C) A OR B OR C
  • D) NOT A AND B AND C
(b)Justify your answer using one row from the table.(1)
(Total for Question 18 is 2 marks)
19
A programmer wants an algorithm that repeatedly asks the user to input a PIN (a string) until the PIN entered is exactly 4 characters long AND every character in it is a digit. You may assume a function IsDigit(character) that returns True if the character passed to it is a digit and False otherwise. Characters in a string can be accessed using position numbers starting at 0, e.g. pin[0] is the first character.

Using OCR Exam Reference Language, write an algorithm that repeats the input process until a valid PIN is entered, then outputs "PIN accepted".
(Total for Question 19 is 6 marks)
20
Complete the truth table below for the expression Output = NOT A OR (B AND NOT C).
ABCNOT ANOT CB AND NOT COutput
000
001
010
011
100
101
110
111
(a)Complete the Output column of the table.(4)
(b)State the number of the eight input combinations for which the expression is False.(1)
(Total for Question 20 is 5 marks)
Mark scheme · P2.4 Boolean Logic

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12

Question 13

Question 14

Question 15

Question 16

Question 17

Question 18

Question 19

Question 20