Boolean Logic and Logic Gates: Question 3
Syllabus 10.1, 10.2, 10.3
An escape-room designer builds a puzzle box with three physical switches labelled P, Q and R, each of which can be set up (1) or down (0). Inside the box, the switches are wired to two gates:
- Gate 1 is a NAND gate, with inputs P and Q.
- Gate 2 is a XOR gate. One of its inputs is the output of Gate 1, and its other input is switch R.
The output of Gate 2, labelled Z, lights a green LED whenever Z = 1.
(a) Write the logic expression for Z in terms of P, Q and R. [2]
(b) Complete the truth table for Z, showing all eight combinations of P, Q and R. [4]
| P | Q | R | Z |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 |
(c) State the number of the eight switch combinations for which the green LED lights. [1]
Show worked solution Hide worked solution
Worked solution
Part (a): Writing the logic expression
Gate 1 is a NAND gate taking P and Q, so its output is P NAND Q, which means NOT (P AND Q).
Gate 2 is a XOR gate that combines this output with switch R, so the final output is:
Z = (P NAND Q) XOR R
Part (b): Building the truth table row by row
For each row, first evaluate P AND Q, then invert it to get P NAND Q, then combine that with R using XOR.
| P | Q | R | P AND Q | P NAND Q | Z = (P NAND Q) XOR R |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 1 |
Working through the two rows where P and Q are both 1: P AND Q = 1, so P NAND Q = 0. XOR with R = 0 gives Z = 0; XOR with R = 1 gives Z = 1. In every other row, P and Q are not both 1, so P AND Q = 0 and P NAND Q = 1, meaning Z is the opposite of R: Z = 1 when R = 0, and Z = 0 when R = 1.
So the completed table for Z is:
| P | Q | R | Z |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Part (c): Counting the lit combinations
Reading down the Z column: 1, 0, 1, 0, 1, 0, 0, 1. There are four rows where Z = 1, namely (0,0,0), (0,1,0), (1,0,0) and (1,1,1).
Final answers
- (a) Z = (P NAND Q) XOR R
- (b) Z values in row order: 1, 0, 1, 0, 1, 0, 0, 1
- (c) The green LED lights for 4 of the 8 switch combinations.