Logic Circuits and Boolean Algebra
The logic circuits that add and remember (half and full adders, SR and JK flip-flops), and simplifying expressions and circuits with the laws of Boolean algebra, De Morgan's laws and Karnaugh maps.
The half adder
A half adder adds two bits and gives two outputs: a sum bit and a carry bit.
A half adder has two inputs, A and B, and two outputs:
- the sum:
S = A XOR B - the carry:
C = A AND B
| A | B | S (sum) | C (carry) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
The carry is 1 only when both bits are 1. Why? In binary, 1 + 1 = 10: write 0 and carry 1.
Watch out:A half adder has no input for a carry from the column before. So on its own it can add only the rightmost column of two binary numbers.
The full adder
A full adder adds three bits, A, B and a carry in, so full adders can be chained.
A full adder adds A, B and a carry in, Cin, from the column before.
- Sum:
S = A XOR B XOR Cin - Carry out:
Cout = (A AND B) OR (Cin AND (A XOR B))
| A | B | Cin | S | Cout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
It is two half adders and an OR gate:
- The first half adder adds A and B.
- The second adds Cin to their sum.
- The OR gate joins the two carries.
Exam:An exam may draw S as one three-input XOR gate. It outputs 1 when an odd number of its inputs are 1.
To add two bytes, chain eight full adders. Each carry out feeds the next carry in.
The SR flip-flop: a circuit that remembers
A flip-flop feeds its outputs back into its own gates, so it remembers one bit.
A flip-flop feeds its outputs back into its own gates. So its output also depends on what it was before. It stores one bit.
An SR flip-flop made of two NOR gates has:
- inputs S (set) and R (reset)
- outputs Q and Q̄ (NOT Q)
| S | R | What happens |
|---|---|---|
| 1 | 0 | set: Q becomes 1 |
| 0 | 1 | reset: Q becomes 0 |
| 0 | 0 | no change: Q keeps whatever it was. This is the memory. |
| 1 | 1 | not allowed: both outputs become 0, so Q̄ is no longer the opposite of Q |
Watch out:On NAND gates it works the other way: a 0 sets or resets, not a 1.
SRAM stores each bit in a flip-flop.
SR flip-flop (two NOR gates), from Q = 0
S R | Q Q̄
1 0 | 1 0 set
0 0 | 1 0 no change: remembers 1
0 1 | 0 1 reset
0 0 | 0 1 no change: remembers 0
1 1 | 0 0 not allowed:
Q and Q̄ are both 0The JK flip-flop
A JK flip-flop is an SR flip-flop with a clock and no forbidden input.
A JK flip-flop changes the SR flip-flop in two ways:
- It adds a clock. Q changes only when a clock pulse arrives. So every flip-flop in a register (a group of flip-flops) changes together.
- It removes the SR's forbidden input.
J acts like set, and K acts like reset.
| J | K | Q next | Name |
|---|---|---|---|
| 0 | 0 | Q | no change |
| 0 | 1 | 0 | reset |
| 1 | 0 | 1 | set |
| 1 | 1 | NOT Q | toggle: Q flips to its opposite |
Remember:J = K = 1 is the input the SR could not take. So all four input combinations are valid. The JK flip-flop never reaches an invalid state.
Boolean algebra and De Morgan's laws
Boolean algebra writes AND as a dot and OR as a plus; De Morgan's laws move a NOT through a bracket.
| Written | Means |
|---|---|
A.B | A AND B |
A + B | A OR B |
| A with a bar over it | NOT A. This page types the bar as A'. |
De Morgan's laws:
(A.B)' = A' + B'(A + B)' = A'.B'
Remember:Break the bar and change the sign.
How to simplify an expression:
- Write one line per step.
- Name the law you used on each line. Examples: a common factor,
X + X' = 1,X.1 = X,X + X'.Y = X + Y. - Check with a truth table. Every line must give the same column.
Q = (A.B)' . (A + B)
= (A' + B') . (A + B) De Morgan
= A'.A + A'.B + B'.A + B'.B
multiply out
= 0 + A'.B + A.B' + 0 X.X' = 0
= A'.B + A.B' that is A XOR B
Q = A.B.C + A.B.C' + A'.B.C
= A.B.(C + C') + A'.B.C
common factor A.B
= A.B + A'.B.C C + C' = 1
= B.(A + A'.C) common factor B
= B.(A + C) A + A'.C = A + C
= A.B + B.C multiply outThe laws by name, one per line
Write one law per line and name it beside the line, because most marks are for the working.
Write one law per line. Name it beside the line, as mark schemes do.
- Most laws come in pairs: an AND form and an OR form.
- Each law is true on every row of its truth table. That is what makes a step legal.
Exam:Most of the marks are for the working: one mark for each different law used correctly. So write every line.
A useful order:
- De Morgan, to break a bar over a bracket
- double negation:
X'' = X - multiply out, or take a common factor
- last, tidy up with complement, identity, annulment, absorption and redundancy
law AND form OR form
identity X.1 = X X + 0 = X
annulment X.0 = 0 X + 1 = 1
idempotent X.X = X X + X = X
complement X.X' = 0 X + X' = 1
double negation X'' = X
absorption X.(X + Y) = X X + X.Y = X
distributive X.(Y + Z) = X.Y + X.Z
X + Y.Z = (X + Y).(X + Z)
redundancy X + X'.Y = X + Y
De Morgan (X.Y)' = X' + Y'
(X + Y)' = X'.Y'
Q = (A' + B')' + A.B'
= A''.B'' + A.B' De Morgan
= A.B + A.B' double negation
= A.(B + B') distributive
= A.1 complement
= A identityKarnaugh maps
A Karnaugh map is a truth table folded into a grid; loops of 1s give the simplest sum of products.
A Karnaugh map is a truth table folded into a grid. Neighbouring cells differ in one input only.
How Cambridge draws it:
| Across | Down | |
|---|---|---|
| Four inputs | AB | CD |
| Three inputs | BC | A |
The pairs go in the order 00, 01, 11, 10.
Rules for the loops:
- Loop the 1s in rectangles of 1, 2, 4, 8 or 16 cells.
- Make the loops as large and as few as possible.
- Loops may overlap where that helps.
- Loops wrap round the edges, so the four corners are neighbours.
Each loop is one term. Keep the inputs that stay the same across the loop. Drop the inputs that change.
Remember:The loops give the simplest sum of products: AND terms joined by OR, like B'.D' + B.D.
AB
00 01 11 10
CD 00 1 0 0 1
01 0 1 1 0
11 0 1 1 0
10 1 0 0 1
loops:
the four corners B = 0, D = 0 -> B'.D'
the middle square B = 1, D = 1 -> B.D
Z = B'.D' + B.DFilling the map from a sum of products
Fill the map first: each four-letter term of the sum of products is one cell holding 1.
A question gives a truth table, or a sum of products whose terms each use all four letters. For each term:
- Turn it into bits: a letter with no bar is 1, and a letter with a bar is 0.
- Read A and B for the column, and C and D for the row.
- Put a 1 in that cell.
Then put a 0 in every cell that no term names.
Watch out:The third column and the third row are 11, not 10.
From a truth table, each row that outputs 1 is one cell.
Example:The 6 terms below give 6 cells holding 1. A.B'.C.D' is A = 1, B = 0, C = 1, D = 0: column 10, row 10.
Z = A'.B'.C.D' + A'.B'.C.D + A.B'.C.D'
+ A.B'.C.D + A.B.C.D' + A.B.C.D
term A B C D column row
A'.B'.C.D' 0 0 1 0 00 10
A'.B'.C.D 0 0 1 1 00 11
A.B'.C.D' 1 0 1 0 10 10
A.B'.C.D 1 0 1 1 10 11
A.B.C.D' 1 1 1 0 11 10
A.B.C.D 1 1 1 1 11 11
AB
00 01 11 10
CD 00 0 0 0 0
01 0 0 0 0
11 1 0 1 1
10 1 0 1 1From the loops to the simplest form and a smaller circuit
Take a common factor out of the K-map's answer, and the circuit needs fewer gates.
The loops of the map above give the simplest sum of products: Z = A.C + B'.C.
A question then often asks for the simplest form, using Boolean algebra:
- Look for a letter that every term keeps. Both loops keep C = 1, so C is a common factor.
- The distributive law takes it outside a bracket:
Z = C.(A + B').
| Expression | Gates |
|---|---|
A.C + B'.C | 4 gates |
C.(A + B') | 3 gates |
The circuit shrinks because C is ANDed once instead of twice.
Remember:D has no gate at all. Both loops cover D = 0 and D = 1, so D dropped out.
loops of the map above
A = 1, C = 1 -> A.C
B = 0, C = 1 -> B'.C wraps round
Z = A.C + B'.C the K-map's answer
= C.(A + B') distributive law:
common factor C
A.C + B'.C NOT, AND, AND, OR
C.(A + B') NOT, OR, ANDAND| A | B | Output |
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
KEY TERMS
CHECK YOURSELF
1.Using De Morgan's law, what is NOT (A AND B) equal to?
2.In a Karnaugh map, why are the columns ordered 00, 01, 11, 10?
3.In an SR flip-flop built from two NOR gates, which input is not allowed?
4.A JK flip-flop has J = 1 and K = 1. What happens on the next clock pulse?
5.A half adder has inputs A and B. What are its two outputs?
6.Which law is used when X + X' is replaced by 1?
7.A K-map gives Z = A.B' + A.D. What is its simplest form?
8.A four-input K-map has AB across the top and CD down the side, both in the order 00, 01, 11, 10. Which cell holds the term A.B'.C.D'?