Study Guide

More Logic Gates

NAND and NOR, predicted from AND, OR and NOT; XOR (EOR), discovered from a staircase light; how the six gates compare; the standard symbol for each; and what happens when one gate's output feeds another.

Lesson 2.2 Boolean Logic

For: Cambridge IGCSE Computer Science (ages 14 to 16), after Lesson 1; useful for AS level revision

Stage: Think

What do you remember?

Before meeting three new logic gates, check what you remember of the last three and their truth tables.

Check your understanding

An OR gate has inputs A and B. Which inputs make its output 0?
Show the answer

Answer: C. A = 0 and B = 0: only when neither of the inputs is 1.

OR’s output is 0 only when both inputs are 0.

So far each gate has worked alone. What happens if the output of one gate goes straight into another?

Gate 1, AND, takes A and B. Gate 2, NOT, takes the output of gate 1. The output of gate 2 is Q. Q = NOT (A AND B)
An AND gate whose output goes into a NOT gate: Q = NOT (A AND B)

Under the drawing, the same circuit is written in words: Q = NOT (A AND B). The brackets show which part is worked out first. This written form, a logic expression, is the subject of the third lesson.

Stage: Predict

Predict: AND, then NOT

Think it through

Before completing anything, predict: will this pair of gates give 1 in more rows than AND alone, or fewer?

Show what happens

More: AND gives 1 in one row, so after NOT the pair gives 1 in the other three.

Work it out row by row. First the AND output (the working column, given here), then turn it round.

AND, then NOT
Gate 1, AND, takes A and B. Gate 2, NOT, takes the output of gate 1. The output of gate 2 is Q. Q = NOT (A AND B)
Q = NOT (A AND B)
ABA AND B (working)Q
000
010
100
111

    Show the completed table
    ABA AND BQ
    0001
    0101
    1001
    1110

    Two gates that always work together like this are made as one gate: NAND, short for NOT AND. A NAND gate’s output is 0 only when both inputs are 1. In every row it gives the opposite of AND.

    Stage: Predict

    And OR, then NOT?

    Think it through

    Now an OR gate followed by a NOT gate. In how many rows do you expect the output to be 1? Decide before you complete the table.

    Show what happens

    One row: OR gives 1 in three rows and 0 in one, so after NOT only one row gives 1.

    OR, then NOT
    Gate 1, OR, takes A and B. Gate 2, NOT, takes the output of gate 1. The output of gate 2 is Q. Q = NOT (A OR B)
    Q = NOT (A OR B)
    ABA OR B (working)Q
    000
    011
    101
    111

      Show the completed table
      ABA OR BQ
      0001
      0110
      1010
      1110

      This pair is also made as one gate: NOR, short for NOT OR. A NOR gate’s output is 1 only when both inputs are 0, the opposite of OR in every row.

      NAND does not mean “neither input is 1”. The NOT in NAND turns round the output of AND, not each input. Check the row A = 1, B = 0: AND gives 0, so NAND gives 1, even though one input is 1. “Neither input is 1” is the rule for NOR.

      Check your understanding

      In how many of the four rows do AND and NAND give the same output?
      Show the answer

      Answer: B. None: NAND is AND turned round in every row.

      NAND and AND disagree in every row, and so do NOR and OR.

      Stage: Experiment

      The staircase light

      A staircase has a light switch at the bottom and another at the top, so you can switch the light on as you go up and off when you reach the top. Both switches start down, and the light is off.

      Think it through

      Someone flicks the bottom switch up: the light comes on. At the top, they flick the top switch up too. Is the light on or off now?

      Show what happens

      Off. Each flick changes the light, so the second flick turns it off again, even though both switches are now up.

      The staircase light

      Test all four positions of the two switches. Predict each time.

      The rule and the complete table

      This is an XOR gate. Exclusive OR: the output is 1 when the inputs are different. Q = A XOR B

      Bottom switch upTop switch upLight on
      000
      011
      101
      110

      Check your understanding

      What do the positions with the light on have in common?
      Show the answer

      Answer: C. The two switches are in different positions.

      A gate whose output is 1 when its inputs are different is XOR, exclusive OR: one or the other, but not both. Cambridge’s syllabus also writes it EOR. An XOR gate differs from OR in just one row, 11, where OR gives 1 and XOR gives 0.

      Stage: Discover

      Six gates side by side

      Think it through

      You now know six gates: NOT, AND, OR, NAND, NOR and XOR. Without looking back, which two pairs of two-input gates are exact opposites of each other?

      Show what happens

      AND and NAND; OR and NOR.

      ABANDNANDORNORXOR
      0001010
      0101101
      1001101
      1110100

      NOT has one input, so it is not in this table: it gives 1 for input 0 and 0 for input 1.

      Check your understanding

      Which two gates give an output of 1 in exactly one row of the table?
      Show the answer

      Answer: B. AND and NOR.

      AND is 1 only for 11; NOR is 1 only for 00. Learning which row is special for each gate is a quick way to tell them apart.

      If you are unsure of any row, test it here. Choose a gate, set the inputs and read the output; the gate’s table is shown with the current row marked.

      All six gates

      AND gate

      The output is 1 only when both inputs are 1. Q = A AND B

      Truth table for AND
      ABQ
      000
      010
      100
      111

      OR gate

      The output is 1 when at least one input is 1. Q = A OR B

      Truth table for OR
      ABQ
      000
      011
      101
      111

      NOT gate

      The output is the opposite of the input. Q = NOT A

      Truth table for NOT
      AQ
      01
      10

      NAND gate

      NOT AND: the output is 0 only when both inputs are 1. Q = NOT (A AND B)

      Truth table for NAND
      ABQ
      001
      011
      101
      110

      NOR gate

      NOT OR: the output is 1 only when both inputs are 0. Q = NOT (A OR B)

      Truth table for NOR
      ABQ
      001
      010
      100
      110

      XOR gate

      Exclusive OR: the output is 1 when the inputs are different. Q = A XOR B

      Truth table for XOR
      ABQ
      000
      011
      101
      110

      Stage: Predict

      The standard symbols

      Each gate has a standard symbol, so a circuit can be drawn and read anywhere. These are the three from the last lesson. Inputs come in on the left and the output leaves on the right.

      Think it through

      The small circle on NOT’s output means “turn the result round”. Predict: what do the NAND and NOR symbols look like? Sketch them.

      Show what happens

      NAND is the AND symbol with the small circle on its output; NOR is the OR symbol with the circle.

      Go deeper The three gates described in words
      • Gate 1: a curved back, a pointed front and a small circle on the output.
      • Gate 2: a flat back and a round front, with nothing on the output.
      • Gate 3: a curved back with a second curve just behind it, and a pointed front, with nothing on the output.

      Check your understanding

      Which gate is Gate 1?
      Show the answer

      Answer: A. NOR: an OR shape with a small circle on its output.

      Gate 1 is NOR, Gate 2 is AND and Gate 3 is XOR.

      Stage: Experiment

      One gate into another

      You have already seen that AND followed by NOT behaves like NAND. Any gate’s output can be another gate’s input: that is how a logic circuit is built.

      Gate 1, OR, takes A and B. Gate 2, AND, takes the output of gate 1 and C. The output of gate 2 is Q. Q = (A OR B) AND C
      An OR gate feeding an AND gate: Q = (A OR B) AND C
      1. Start with the gate that has only inputs going in. The OR gate gets A = 0 and B = 1. OR needs at least one 1, so its output is 1.
      2. Carry that value along the wire. The OR gate’s output, 1, is now one input of the AND gate; C = 0 is the other.
      3. Work out the last gate. AND needs both inputs to be 1, and C is 0, so Q = 0.

      The OR gate gave 1, but Q is still 0: every gate on the way matters, so each one is worked out in turn.

      Think it through

      Trace one row through this circuit: A = 0, B = 1, C = 1. What comes out of the OR gate, and what comes out at Q?

      Show what happens

      The OR gate gets 0 and 1, so it outputs 1. The AND gate then gets that 1 and C = 1, so Q = 1.

      Complete the working column and Q for two rows
      Gate 1, OR, takes A and B. Gate 2, AND, takes the output of gate 1 and C. The output of gate 2 is Q. Q = (A OR B) AND C
      Q = (A OR B) AND C
      ABCA OR B (working)Q
      101
      110

        Show the completed table
        ABCA OR BQ
        10111
        11010

        The next lesson shows how to do this for every row at once, and how to write such a circuit down as a logic expression.

        Stage: Apply

        Choose the gate

        Apply it

        A machine’s warning light comes on unless both of its safety checks pass. Which single gate gives the warning light?
        Show the answer

        Answer: C. NAND: the light is 0 only when both checks are 1.

        The light must be on whenever at least one check fails: that is NAND.

        Apply it

        A quiz has two buzzers. The screen shows “Answer!” only if exactly one team presses; if both press together it shows nothing. Which gate?
        Show the answer

        Answer: B. XOR: the output is 1 only when the inputs differ.

        “Exactly one, not both” is XOR.

        Check your understanding

        Priya says: “NOR gives 1 when exactly one input is 0.” What is wrong?
        Show the answer

        Answer: A. NOR gives 1 only when both inputs are 0; one 0 and one 1 gives 0.

        NOR is 1 only for the row 00.

        Stage: Consolidate

        Show what you know

        Think it through

        Explain the difference between OR and XOR in two sentences, and give a real situation for each.

        Show a model answer

        A good answer names the row 11. For example: “OR gives 1 if either input or both are 1, like a doorbell that rings from the front or the back door. XOR gives 1 only when exactly one input is 1, like the staircase light, where both switches up turn it off.”

        Complete the table for Q = A XOR B, then for NAND below
        ABQ
        00
        01
        10
        11

          Show the completed table
          ABQ
          000
          011
          101
          110
          Q = A NAND B
          ABQ
          00
          01
          10
          11

            Show the completed table
            ABQ
            001
            011
            101
            110

            Think it through

            Which gate do you find hardest to remember, and what will help you remember it?

            Show a model answer

            There is no wrong answer. If it is NAND or NOR, one reliable method is to work out AND or OR first, then turn every output round.

            • NAND is AND turned round (0 only for 11); NOR is OR turned round (1 only for 00).
            • XOR (EOR) gives 1 when the inputs are different. It differs from OR only in the row 11.
            • The symbols: AND has a flat back, OR a curved back, XOR an extra curve; a small circle on the output means NOT.
            • A gate’s output can be another gate’s input: work out the first gate before the next.

            Sources and scope

            • What this lesson is. The second of four draft lessons on Boolean logic, written for this site, awaiting the site owner’s editorial review. Its curriculum links are provisional: the wording of each linked specification point has been checked against the published specification, but no link has yet been verified by the site owner. The links show where the lesson may help with a course; they do not imply that any examination board has reviewed or endorsed it.
            • Symbols. The diagrams are original drawings in the distinctive-shape style. The syllabus shows the symbols to use in its section 4, page 34, as drawings; compare them by eye before an examination.
            • Original material. The machine warning light, the quiz buzzers and Priya’s claim are fictional. The two-way staircase light is a common real-world example of XOR.