AQA 7517, section 4.6.4.1
A logic gate is a tiny electronic circuit that takes one or more binary inputs (0 or 1) and gives a binary output, according to a fixed rule. Every part of a processor is built from millions of gates.
A truth table lists every possible combination of inputs, and the output for each.
The six gates
The specification uses the ANSI/IEEE distinctive shape symbols. In words: AND has a flat back and a rounded front (like a "D"). OR has a curved back and a pointed front. NOT is a triangle. A small circle (a "bubble") on an output means inverted, so NAND is AND plus a bubble, and NOR is OR plus a bubble. XOR is OR with an extra curved line at the back.
NOT
Output is the opposite of the input. Written or NOT A.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
AND
Output is 1 only if both inputs are 1. Written or A AND B.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR
Output is 1 if at least one input is 1. Written or A OR B.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
XOR
Output is 1 if the inputs are different (exactly one is 1). Written or A XOR B.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NAND
The opposite of AND: NOT (A AND B). Written .
| A | B | A NAND B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOR
The opposite of OR: NOT (A OR B). Written .
| A | B | A NOR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
Circuits with several gates
The output of one gate can be the input of another. To work out a circuit's behaviour, handle the gates in order, from the inputs to the output.
From a circuit to a truth table
The circuit has an AND gate on A and B, a NOT gate on C, and an OR gate that combines them.
To complete the truth table for three inputs there are rows. Add a column for each internal result.
| A | B | C | A AND B | NOT C | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
From a circuit to a Boolean expression
Write the expression for each gate in turn. For the circuit above:
From a Boolean expression to a circuit
Work from the inside out. For :
- Use a NOT gate on A.
- Use an OR gate on B and C.
- Use an AND gate to combine the two results.
The half adder
An adder adds binary digits. A half adder adds two single bits, A and B, and gives a sum and a carry.
| A | B | Carry | Sum |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Look at the columns: the sum is A XOR B, and the carry is A AND B.
So the circuit for a half adder is one XOR gate and one AND gate, both fed with A and B.
The full adder
A half adder can't handle a carry in from a previous column. A full adder adds three bits: A, B and a carry in (), giving a sum and a carry out ().
| A | B | Sum | ||
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
It's built from two half adders and an OR gate:
- The first half adder adds A and B, giving a partial sum and a carry .
- The second half adder adds and , giving the final Sum and a carry .
- An OR gate combines the two carries: .
Adding multi-bit numbers. Join several full adders in a row, with the carry out of one feeding the carry in of the next (a ripple carry adder). A 4-bit adder uses one half adder (or a full adder with carry in 0) for the rightmost bit, and full adders for the other three.
The D-type flip-flop
A flip-flop is a circuit that can store one bit, and so is used as a memory unit. The edge-triggered D-type flip-flop has:
- a D input (the data to store);
- a clock input;
- a Q output (the stored bit).
It works like this: when the clock signal changes from low to high (the rising edge), the flip-flop copies D to Q and then holds that value. Changes in D between clock edges are ignored. So Q stays the same until the next clock edge.
| Clock | D | Q after |
|---|---|---|
| Rising edge | 0 | 0 |
| Rising edge | 1 | 1 |
| No edge | any | unchanged |
A set of D-type flip-flops, one for each bit, makes a register, and registers are used in the processor and as the basis of memory. You don't need to know how the flip-flop works inside.
Worked example
Task: write the Boolean expression for this circuit, and complete its truth table: and both go into a NAND gate. The output goes into an XOR gate with to give .
Expression: .
| A | B | A NAND B | Q = A XOR (A NAND B) |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Exam tip: for a truth table, list all the input combinations in binary counting order, add a column for each intermediate gate, and fill them in one at a time. Remember the half adder (XOR for sum, AND for carry) and that a full adder is two half adders and an OR.
Check yourself
What is the output of a NOR gate when both inputs are 0?
- NOR is the opposite of OR, and OR gives 0 for (0, 0).
Which two gates make a half adder, and what does each calculate?
An XOR gate gives the sum, and an AND gate gives the carry.
Write the expression for a circuit with an OR gate on A and B, whose output is inverted
, which is the same as a NOR gate.
What does an edge-triggered D-type flip-flop do?
It stores one bit. On the clock's rising edge it copies the D input to the output Q, and holds that value until the next edge.