Logic and computer systems · GCSE · OCR J277 2.4.1, AQA 8525 3.4.2, Edexcel 1CP2 1.3.1 · about 15 min
Combining gates, Boolean expressions, XOR, and the half adder.
[1 mark]In Q = (A AND B) OR (NOT C), A = 0, B = 1 and C = 1. What is Q?
[1 mark]In Q = (A AND B) OR (NOT C), A = 0, B = 0 and C = 0. What is Q?
[1 mark]When does XOR output 1?
[1 mark]In a half adder, which gate gives the carry bit?
[1 mark]What does this program print?
def XOR(a, b): return 1 if a != b else 0
for a, b in [(1, 1), (1, 0)]:
print(a & b, XOR(a, b))[1 mark]"Beep if the robot is close and moving, or it has bumped." Which expression matches?
Write AND(a, b) and XOR(a, b) as functions of 0s and 1s. XOR must be built from AND, OR and NOT functions you also write, as (A OR B) AND NOT (A AND B), not with !=. Print the half adder's truth table as four lines in the form A=1 B=1 carry=1 sum=0.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() def AND(a, b): return 1 if a and b else 0 def OR(a, b): return 1 if a or b else 0 def NOT(a): return 1 - a
Plan your program here, then type it in and press Run.
NOT (A AND B) is always the same as (NOT A) OR (NOT B) by printing both columns.