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
So far each gate has worked alone. What happens if the output of one gate goes straight into another?
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?
- Hint 1: AND gives 1 in only one row. What does NOT do to each of AND’s outputs?
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.
| A | B | A AND B (working) | Q |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 0 | |
| 1 | 1 | 1 |
- Use the working column: NOT turns each value in it round.
Show the completed table
| A | B | A AND B | Q |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
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.
- Hint 1: In how many rows is OR’s output 1? What does NOT do to that?
Show what happens
One row: OR gives 1 in three rows and 0 in one, so after NOT only one row gives 1.
| A | B | A OR B (working) | Q |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 1 | |
| 1 | 1 | 1 |
Show the completed table
| A | B | A OR B | Q |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 |
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
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?
- Hint 1: They wanted the light off when they reached the top.
Show what happens
Off. Each flick changes the light, so the second flick turns it off again, even though both switches are now up.
Test all four positions of the two switches. Predict each time.
Set the inputs
Predict the output (Light on): 0 or 1?
Test it
Light on:
| Bottom switch up | Top switch up | Light on |
|---|---|---|
| 0 | 0 | ? |
| 0 | 1 | ? |
| 1 | 0 | ? |
| 1 | 1 | ? |
Challenge: Find the positions in which the light is on. What do they have in common?
0 of 4 combinations tried.
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 up | Top switch up | Light on |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Check your understanding
Show the answer
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?
- Hint 1: Two of the gates were made by adding NOT to another.
Show what happens
AND and NAND; OR and NOR.
| A | B | AND | NAND | OR | NOR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 | 1 | 0 | 0 |
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
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.
Output Q:
AND gate
The output is 1 only when both inputs are 1. Q = A AND B
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR gate
The output is 1 when at least one input is 1. Q = A OR B
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
NOT gate
The output is the opposite of the input. Q = NOT A
| A | Q |
|---|---|
| 0 | 1 |
| 1 | 0 |
NAND gate
NOT AND: the output is 0 only when both inputs are 1. Q = NOT (A AND B)
| A | B | Q |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOR gate
NOT OR: the output is 1 only when both inputs are 0. Q = NOT (A OR B)
| A | B | Q |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
XOR gate
Exclusive OR: the output is 1 when the inputs are different. Q = A XOR B
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
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.
AND: a flat back and a round front: Q = A AND B OR: a curved back and a pointed front: Q = A OR B NOT: a triangle with a small circle: Q = NOT A
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.
- Hint 1: NAND is AND, then NOT.
Show what happens
NAND is the AND symbol with the small circle on its output; NOR is the OR symbol with the circle.
AND: Q = A AND B NAND: AND with a circle: Q = A NAND B OR: Q = A OR B NOR: OR with a circle: Q = A NOR B XOR (EOR): OR with an extra curve at the back: Q = A XOR B NOT: Q = NOT A
Gate 1 Gate 2 Gate 3
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
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.
- 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.
- 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.
- 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?
- Hint 1: Work out the OR gate first: its output is one of the AND gate’s inputs.
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.
| A | B | C | A OR B (working) | Q |
|---|---|---|---|---|
| 1 | 0 | 1 | ||
| 1 | 1 | 0 |
- First the OR gate, which becomes the working column; then AND it with C.
Show the completed table
| A | B | C | A OR B | Q |
|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 0 |
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
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
Show the answer
Answer: B. XOR: the output is 1 only when the inputs differ.
“Exactly one, not both” is XOR.
Check your understanding
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.”
| A | B | Q |
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
Show the completed table
| A | B | Q |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| A | B | Q |
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
Show the completed table
| A | B | Q |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
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.
A logic gate whose output is 1 only when both of its inputs are 1.
Reasoning with values that are either true or false (1 or 0), combined with operations such as AND, OR and NOT.
A closed path that electricity flows around, made of connected components. A logic gate is a very small circuit, made of transistors.
A piece of information that goes into a system for it to use, such as whether a card is valid. In a logic gate each input is 0 or 1.
Logic gates joined together, so that the output of one gate becomes an input of another.
A written description of a logic circuit using gate names and brackets, such as Q = (A AND B) OR C.
A small electronic circuit that takes one or more binary inputs and produces one binary output according to a fixed rule. A NOT gate has exactly one input.
NOT AND: a logic gate whose output is 0 only when both inputs are 1. Its outputs are the opposite of AND’s in every row.
NOT OR: a logic gate whose output is 1 only when both inputs are 0. Its outputs are the opposite of OR’s in every row.
A logic gate whose output is 1 when at least one of its inputs is 1, including when both are.
What a system produces from its inputs, such as whether a door unlocks. A logic gate has one output, 0 or 1.
A table listing every possible combination of a logic gate’s or circuit’s inputs, with the output for each.
An extra column in a truth table for the output of one gate inside a circuit, worked out before the gates that use it.
Exclusive OR: a logic gate whose output is 1 when its two inputs are different. Also written EOR.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.