The answersDownload the PDF
Worksheet

A8.1 Logic gates and notation

Boolean algebra and logic circuits · A level · OCR H446 1.4.3, AQA 7517 4.6.4.1, Eduqas A500QS 1.2 · about 20 min

BugBotLab
NameClassDate

What this lesson is about

NOT, AND, OR, XOR, NAND and NOR, the notation each board uses, and why NAND alone can build anything.

Questions 6 marks in all

  1. [1 mark]When does a NAND gate output 0?

    1. AOnly when both inputs are 1
    2. BOnly when both inputs are 0
    3. CWhen the inputs are different
    4. DNever
  2. [1 mark]When does a NOR gate output 1?

    1. AOnly when both inputs are 0
    2. BWhen at least one input is 1
    3. COnly when both inputs are 1
    4. DWhen the inputs are different
  3. [1 mark]In OCR notation, which expression means A XOR B?

    1. AA ⊻ B
    2. BA ∨ B
    3. CA ∧ B
    4. D¬(A ∧ B)
  4. [1 mark]What does this program print?

    a = 1
    b = 0
    print(1 - (a & b), 1 - (a | b), a ^ b)
  5. [1 mark]What does this program print?

    a = 1
    print(~a, 1 - a, a ^ 1)
  6. [1 mark]Why are NAND and NOR called universal gates?

    1. AAny logic circuit can be built from NAND gates alone, or from NOR gates alone
    2. BThey are used in every processor made
    3. CThey have the most rows in their truth tables
    4. DThey work with any number of inputs

The task: everything from NAND

You are given NAND(a, b), which takes two bits (each 0 or 1) and returns 0 or 1. Write four functions, each taking bits and returning 0 or 1, built only by calling NAND or the gates you have already built from it: NOT(a), AND(a, b), OR(a, b) and XOR(a, b). Your program may not use and, or, not, comparisons such as ==, a minus sign, or the operators &, |, ^ and ~. Then use loops to print one line for each of the four input combinations, in binary order, in exactly this form: A=0 B=1 NOT_A=1 AND=0 OR=1 XOR=1

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

def NAND(a, b):
    return [1, 1, 1, 0][2 * a + b]

def NOT(a):
    return 0

def AND(a, b):
    return 0

def OR(a, b):
    return 0

def XOR(a, b):
    return 0

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/a8-1-logic-gates-and-notation/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Build NOT, AND and OR from NOR alone. Which is easier to build from NOR than from NAND?
  2. How many NAND gates does your XOR use in total, counting the ones inside the gates it calls? Can you do it in four?
  3. Write A ⊻ B using only AND, OR and NOT, in both OCR and AQA notation.