Logic Gates and Logic Circuits
The six logic gates and their truth tables, and how to build a logic circuit, a truth table or a logic expression from a problem statement or from either of the other two.
WATCH IT EXPLAINED
Six gates, and the AS rule of two inputs
Every AS circuit uses just six gates, and every gate except NOT has exactly two inputs.
The six gates are NOT, AND, OR, NAND, NOR and XOR (also written EOR).
| A | B | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
- AND is 1 only when BOTH inputs are 1.
- OR is 1 when AT LEAST ONE input is 1.
- XOR is 1 when the inputs are DIFFERENT.
- NAND and NOR are AND and OR with the output inverted. NAND is 0 only when both are 1. NOR is 1 only when both are 0.
- NOT has one input and flips it: NOT 0 = 1, NOT 1 = 0.
Exam:In AS questions every gate except NOT has exactly two inputs. So A AND B AND C is drawn as two AND gates: (A AND B) AND C.
Watch out:Draw each shape accurately. An OR drawn like an AND is wrong.
Logic expressions: gate names as operators
A logic expression writes a whole circuit on one line, using the gate names as operators.
A logic expression is a circuit written as words:
- AND, OR, NAND, NOR and XOR go between two inputs:
A AND B. - NOT goes in front:
NOT A. - Brackets show which gate works first.
NOT covers only the letter or the bracket straight after it.
| You write | It means | It does NOT mean |
|---|---|---|
NOT A AND B | (NOT A) AND B | NOT (A AND B) |
In the figure, these two disagree on 2 of the 4 rows.
Remember:An expression may join three inputs, as in A AND B AND C. But every gate except NOT has two inputs, so it is drawn as (A AND B) AND C.
NOT covers only the next letter or
bracket:
NOT A AND B = (NOT A) AND B
A B | (NOT A) AND B | NOT (A AND B)
0 0 | 0 | 1
0 1 | 1 | 1
1 0 | 0 | 1
1 1 | 0 | 0
Gate names are the operators:
(A NOR B) XOR (B NAND C)How many rows, and in what order
A truth table has one row for every input combination, written in binary counting order.
A truth table has one row for every combination of the inputs. Each extra input doubles the number of rows: n inputs give 2^n rows.
| Inputs | Rows |
|---|---|
| 2 | 4 |
| 3 | 8 |
| 4 | 16 |
How to write the input columns:
- Start from all 0s.
- Count up in binary, one row at a time.
- Check the pattern: the last input column alternates 0 and 1. Each column to its left changes half as often.
Watch out:Write every input row before you work out any output. Then no row can go missing.
n inputs give 2^n rows
2 inputs: 4 rows
3 inputs: 8 rows
4 inputs: 16 rows
3 inputs in binary counting order:
A B C
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 0 1 0 1 0 1 0 1 changes every row
B 0 0 1 1 0 0 1 1 every 2 rows
A 0 0 0 0 1 1 1 1 every 4 rowsFrom an expression to a circuit
Build the circuit from the inside out: innermost brackets first, the outside gate last.
Steps:
- Innermost brackets first. Their gates are the first ones you draw.
- NOT gates. A NOT in front of a bracket is a NOT gate placed straight after that bracket's gate. A NOT in front of a letter goes on that input's wire.
- The last gate. The two-input gate outside every bracket is the last gate. Its output is the answer.
Wires: give each input one wire from the left. If the expression uses an input twice, split that wire.
Exam:Read your circuit back as an expression. It must say the question again. The marks are for gates drawn with the right inputs.
X = NOT (A NOR B) AND (B XOR C)
1 Innermost brackets first:
P = A NOR B
R = B XOR C
2 The NOT is in front of (A NOR B):
Q = NOT P
3 AND is the two-input gate outside
every bracket, so it is the last
gate:
X = Q AND R
CHECK: read it back.
X = Q AND R
= NOT (A NOR B) AND (B XOR C)From an expression or a circuit to a truth table
Fill a truth table one gate at a time, with a working column for each gate.
- Write all the input rows first, in counting order.
- Give each gate's output a letter, such as P, Q and R.
- Give each letter its own working column.
- Fill the table one column at a time, top to bottom. Work out each column from columns already filled.
- Fill the output column last.
Why this works: you only ever work out one gate at a time. A slip shows up in its own column.
Exam:Mark schemes often give one mark for each block of four rows of the output column. So check each block.
X = (A NAND B) XOR (B OR NOT C)
P = A NAND B Q = NOT C
R = B OR Q X = P XOR R
A B C | P Q R | X
0 0 0 | 1 1 1 | 0
0 0 1 | 1 0 0 | 1
0 1 0 | 1 1 1 | 0
0 1 1 | 1 0 1 | 0
1 0 0 | 1 1 1 | 0
1 0 1 | 1 0 0 | 1
1 1 0 | 0 1 1 | 1
1 1 1 | 0 0 1 | 1From a circuit to an expression
Read a circuit forwards and write what each gate makes on its output wire.
Go from the inputs to the output:
- On the wire leaving each gate, write what that gate makes, in brackets: (A NOR B), (NOT B), and so on.
- A gate joins the words on its two input wires with its own name.
- Where a wire splits, the same words go to each gate it feeds.
- When you reach the output, the words on the last wire are the answer.
Exam:Keep the brackets and do not simplify, even when you can see a shorter answer. The marks are for the circuit as it is drawn, part by part.
METHOD
1 Write A, B and C on the input wires.
2 On each gate's output wire, write
what it makes, in brackets:
the NOR gate: (A NOR B)
the NOT gate: (NOT B)
the AND gate: (NOT B AND C)
NOT B needs no bracket: NOT covers only B
3 The last gate joins the words on
its two input wires:
(A NOR B) XOR (NOT B AND C)
X = (A NOR B) XOR (NOT B AND C)
Do not simplify. Keep the brackets.From a problem statement to a circuit and a table
Turn the words of a problem into letters and gates, then into an expression, a circuit and a table.
- Give each condition a letter. Write down what 1 means for it, such as R = 1 means it is raining.
- Translate the joining words (see the table).
- Write the expression, with brackets, before you draw anything.
- Draw from the innermost bracket outwards.
- Fill the truth table, one column per gate.
| The problem says | You write |
|---|---|
| and | AND |
| or | OR |
| not | NOT |
| unless | AND NOT |
| either one but not both | XOR |
Remember:This is the IGCSE method, used on longer statements.
"The window W opens when the temperature
is high and it is not raining, or when
the humidity is high and it is not
raining."
T = 1 the temperature is high
H = 1 the humidity is high
R = 1 it is raining
W = (T AND NOT R) OR (H AND NOT R)
P = NOT R X = T AND P
Y = H AND P W = X OR Y
CHECK: read the circuit back in words.
It must say the sentence again.From a truth table to an expression and a circuit
From a truth table, write one AND term for each row that outputs 1, then OR the terms together.
This method is called sum of products.
- Take each row where the output is 1.
- Write it as the inputs ANDed together. Put NOT in front of every input that is 0.
- OR all these terms together.
This always gives a correct expression.
To draw it: each three-input AND term becomes two two-input AND gates.
Exam:At AS, the syllabus asks for a correct expression, and the long one is correct. Simplifying it with Boolean algebra is A Level, not AS.
The figure builds the answer from the window's table. The long expression and the short one give the same W on every row.
Rows of the window's table where W = 1:
T H R W
0 1 0 1 -> (NOT T) AND H AND (NOT R)
1 0 0 1 -> T AND (NOT H) AND (NOT R)
1 1 0 1 -> T AND H AND (NOT R)
W = ((NOT T) AND H AND (NOT R))
OR (T AND (NOT H) AND (NOT R))
OR (T AND H AND (NOT R))
CHECK: 3 AND terms
for 3 rows that output 1.Two outputs from one problem, worked end to end
When one problem has two outputs, write one expression for each and share the parts they both need.
- Give each input a letter, and write what 1 means.
- Write one expression for each output, from its own sentence.
- Draw the circuit. A part that both outputs need, here S AND H, is drawn once, and its wire splits.
- Draw the truth table with one column for each output.
- Test each row where an output is 1 against its sentence.
Remember:An expression may join three inputs at once, such as S AND H AND NOT W. A mark scheme may write its answer that way. But in the circuit, every gate except NOT still has two inputs.
S = 1 the controller is switched on
H = 1 the air is too hot
W = 1 the window is open
"The fan F runs when the controller
is on and the air is too hot."
F = S AND H
"The alarm A sounds when the
controller is on, the air is too hot
and the window is not open."
A = S AND H AND NOT W
drawn as (S AND H) AND (NOT W)
S H W | F A
0 0 0 | 0 0
0 0 1 | 0 0
0 1 0 | 0 0
0 1 1 | 0 0
1 0 0 | 0 0
1 0 1 | 0 0
1 1 0 | 1 1
1 1 1 | 1 0
CHECK row 1 1 0: on, too hot, window
shut, so the fan runs and the alarm
sounds.AND| A | B | Output |
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
KEY TERMS
CHECK YOURSELF
1.A truth table has 3 rows where the output is 1. How many AND terms does its sum of products have?
2.What does the expression NOT A AND B mean?
3.A truth table has four inputs. How many rows does it need?
4.At AS, how do you draw A AND B AND C?
5.You draw the circuit for X = NOT (A OR B) AND C. Which gate do you draw last?
6.A question says: write the logic expression for the circuit, and do not simplify it. What do you write?
7.A three-input truth table is written in binary counting order. What is its first input column, from top to bottom?
8.A security light L comes on when it is dark (D = 1) and someone is near (P = 1), or when the test button is pressed (T = 1). Which expression is correct?