Cambridge AS & A Level · Part 3 · Chapter 19
Logic Circuits and Boolean Algebra
How gates add numbers and remember bits, and how a little algebra (or a Karnaugh map) turns a messy truth table into the simplest possible expression. Every figure, task, question and exam question from the chapter is here, with live labs for each idea.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- produce truth tables for logic circuits, including half adders and full adders
- show understanding of a flip-flop (SR, JK)
- Show understanding of Boolean algebra
- Show understanding of Karnaugh maps
➕ 19.01 Logic circuits: the half adder
Chapter 4 introduced the gate symbols and how circuits, truth tables and logic expressions relate. This chapter uses them to build circuits that do real jobs inside the hardware.
Adding two bits is the most basic operation in computing. The result is 0 or 1, but 1 + 1 gives 0 with a carry of 1, and that carry cannot be ignored when the numbers have several bits.
The simplest adding circuit is the half adder. It takes two input bits and outputs a sum bit S and a carry bit C.
| Input | Output | ||
|---|---|---|---|
| A | B | S | C |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Table 19.01 The truth table for a half adder
Look at the columns: C is 1 only when both inputs are 1, which is the AND truth table. S matches XOR (Chapter 4, Section 4.04). So one half adder is simply an AND gate and an XOR gate, each fed from A and B.
That is only one design. NAND and NOR are universal gates: any circuit can be built from NAND gates alone, or NOR gates alone. They are also easy to manufacture, so chip makers prefer them. Figure 19.02 is a half adder made only of NAND gates.
🔬 Lab: probe the NAND half adder
Toggle A and B. Every point in Figure 19.02 lights up when it is 1, and the matching row of Table 19.01 is highlighted.
| A | B | W | X | Y | S | C |
|---|
Show answer
AND (the carry): the first NAND gate (output W) followed by the bottom-right NAND gate, whose two inputs are both joined to W. A NAND with its inputs tied together is a NOT gate, so C = NOT(NOT(A.B)) = A.B.
XOR (the sum): the four NAND gates that produce W, X, Y and S. W feeds the gates making X and Y, and S = NAND(X, Y).
Tap each cell to cycle ? → 0 → 1, then check.
| A | B | W | X | Y | S | C |
|---|
➕ The full adder
To add two multi-bit binary numbers you start with the two least significant bits and work towards the most significant. At each stage the carry from the previous stage must be added in too. A half adder only takes two inputs, so it would need extra circuitry for the carry.
The full adder has three inputs: A, B and the carry in from the previous addition, Cin.
| Input | Output | |||
|---|---|---|---|---|
| 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 |
Table 19.02 The truth table for a full adder
One way to build it uses two half adders and an OR gate:
As before, the whole circuit can be made from NAND gates:
🔬 Lab: inside the full adder (Figure 19.03)
Set A, B and Cin. Watch the first half adder, the second half adder and the OR gate.
My answer
Chain four full adders, one per bit position. The Cout of each adder is wired to the Cin of the next, more significant adder: a ripple-carry adder. The first (least significant) adder has no previous carry, so its Cin is fixed at 0 (or a half adder is used for that bit). The Cout of the last adder is the fifth result bit; if only four bits are kept, a 1 there means overflow. Try it in the lab below.
🔗 Lab: a 4-bit ripple-carry adder
Toggle the bits of the two numbers. Each column is one full adder; the carry ripples from right to left.
🔁 19.02 Sequential logic circuits
Every circuit in this book so far has been a combinational circuit: its output depends only on the input values. In a sequential circuit the output depends on the inputs and on the previous output. That feedback is what lets a circuit remember.
🔒 The SR flip-flop
The SR flip-flop, or latch, is a simple sequential circuit. It can be built with two NAND gates or two NOR gates. Figure 19.05 shows the NOR version.
The two gates are cross-coupled: each output feeds back into the other gate. This has interesting consequences.
- Suppose R, S, Q and Q′ were all 0. That contradicts itself: a NOR gate with two 0 inputs outputs 1.
- Q and Q′ both 1 is also impossible, because a NOR gate outputs 0 if either input is 1.
- So the flip-flop is a two-state device: either Q = 1 and Q′ = 0, or the reverse.
The two rows of Table 19.03 where S and R are both 0 mean no signal is being input. Take the state Q = 1, Q′ = 0 with S = R = 0:
- the top NOR gate has inputs R = 0 and Q′ = 0, so it outputs 1 (Q stays 1);
- the bottom NOR gate has inputs S = 0 and Q = 1, so it outputs 0 (Q′ stays 0).
The state is self-consistent: it is the set state. The same argument works for the unset state, Q = 0 and Q′ = 1. S and R stand for set and reset: S = 0, R = 1 turns a set state into an unset state, and S = 1, R = 0 turns an unset state into a set state.
| Input signals | Initial state | Final state | |||
|---|---|---|---|---|---|
| S | R | Q | Q′ | Q | Q′ |
| 0 | 0 | 1 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 | 1 |
Table 19.03 A representation of a truth table for an SR flip-flop
This is why an SR flip-flop can store 1 bit, and so could be a component of RAM: a value is held, but it can be changed. There are no rows for S = 1 and R = 1, because that leads to an invalid state with Q and Q′ both 0. The circuit must be protected from receiving a signal on R and S at the same time.
The NAND gate version has a similar structure, but the labelling is different: setting is done with S = 0 and R = 1 and resetting with R = 0 and S = 1 (its inputs are "active low").
🔬 Lab: SR flip-flop
Choose the gate type, then change S and R. The log shows each new stable state. Try to break it.
Show answer
The NAND version is drawn in exam question 4 (Summary & Exam tab): S feeds the top NAND gate (output Q), R feeds the bottom one (output Q′), and each output feeds back to the other gate. Q = NAND(S, Q′) and Q′ = NAND(R, Q).
| S | R | Q | Q′ | Meaning |
|---|---|---|---|---|
| 1 | 1 | Q | Q′ | no change (memory) |
| 0 | 1 | 1 | 0 | set |
| 1 | 0 | 0 | 1 | reset |
| 0 | 0 | 1 | 1 | invalid |
The invalid input is now S = R = 0, because a NAND gate outputs 1 whenever any input is 0.
⏱️ The JK flip-flop
Besides the invalid state, a circuit can end up in an uncertain state if the inputs do not arrive at quite the same time. To prevent this, a circuit can have a clock pulse input, which gives a better chance of synchronising the inputs. The JK flip-flop is an example.
Remember that a NAND gate gives a 1 unless all its inputs are 1. In the unset state, Q = 0 and Q′ = 1, the circuit is stable:
- the clock and K both input 0 (the book prints "R" here; in a JK flip-flop it is K);
- so the top-left NAND gate outputs 1;
- which gives two 1 inputs to the top-right NAND gate;
- ensuring Q = 0.
If J now becomes 1 and the clock pulse switches to 1:
- the top-left NAND gate has all its inputs at 1, so it outputs 0;
- this makes the top-right NAND gate output 1 for Q;
- now the bottom-right NAND gate has two 1 inputs, so Q′ becomes 0.
So J is a set input, and by a similar argument K is a clear input. Like the SR flip-flop it stores one bit, with one important difference: if J and K are both 1, Q and Q′ are toggled (they swap values). No combination of inputs leaves the stored value uncertain, so the JK flip-flop is more reliable.
| J | K | Clock | Q |
|---|---|---|---|
| 0 | 0 | ↑ | Q unchanged |
| 1 | 0 | ↑ | 1 |
| 0 | 1 | ↑ | 0 |
| 1 | 1 | ↑ | Q toggles |
Table 19.04 Part of the truth table for a JK flip-flop
🔬 Lab: clock a JK flip-flop
Set J and K, then send a clock pulse. Nothing changes between pulses, whatever J and K do. The timing diagram records every pulse.
Show answer
While the clock is 0, both left-hand NAND gates output 1, so the right-hand pair just holds its state (unchanged, like S = R = 0). When the clock goes to 1:
- J = 0, K = 0: each left gate has a 0 input, still outputs 1: Q unchanged.
- J = 1, K = 0: the top-left gate gets J, clock and the fed-back Q′. If Q′ = 1 it outputs 0 and sets Q = 1. If Q was already 1 then Q′ = 0, it outputs 1 and nothing changes: Q = 1.
- J = 0, K = 1: the mirror image: the bottom-left gate clears it: Q = 0.
- J = 1, K = 1: only the gate whose fed-back output is 1 can fire. If Q = 1, the bottom gate (fed by Q) fires and clears it; if Q = 0, the top gate (fed by Q′) fires and sets it: Q toggles.
🧮 19.03 Boolean algebra basics
Chapter 4 (Section 4.01) introduced logic expressions: propositions joined by Boolean operators. Boolean algebra is a simpler way to write them, plus a set of rules for manipulating them.
With any algebra you must be clear what the symbols mean. Here are four meanings of 1 + 1:
| Statement | Applies to |
|---|---|
| 1 + 1 = 2 | denary arithmetic |
| 1 + 1 = 10 | binary arithmetic |
| 1 + 1 = 0 | bit arithmetic (the sum bit, carry dropped) |
| 1 + 1 = 1 | Boolean algebra |
In Boolean algebra 1 means TRUE, 0 means FALSE and + means OR. So the fourth line reads TRUE OR TRUE is TRUE.
Notations vary: AND and OR are sometimes written ∧ and ∨, and A AND B can be written A.B or AB. This book uses the dot. NOT A, the inverse of A, is written A.
📜 The laws (identities) Table 19.05
| Identity / Law | AND form | OR form |
|---|---|---|
| Identity | 1.A = A | 0 + A = A |
| Null | 0.A = 0 | 1 + A = 1 |
| Idempotent | A.A = A | A + A = A |
| Inverse | A.A = 0 | A + A = 1 |
| Commutative | A.B = B.A | A + B = B + A |
| Associative | (A.B).C = A.(B.C) | (A + B) + C = A + (B + C) |
| Distributive | A + B.C = (A + B).(A + C) | A.(B + C) = A.B + A.C |
| Absorption | A.(A + B) = A | A + A.B = A |
| De Morgan's | A.B = A + B | A + B = A.B |
| Double Complement | A = A | |
Don't worry if some of the names are unfamiliar. Notice that every identity except one has an AND form and an OR form, and you can turn one into the other by swapping each 0 with 1 and each AND with OR. For example 0.A = 0 (FALSE AND A is FALSE) becomes 1 + A = 1 (TRUE OR A is TRUE).
Some identities look like ordinary algebra, with AND acting like multiplication and OR like addition. That is why we talk about products and sums in Boolean algebra.
De Morgan's laws look complicated but are easy to rationalise: the inverse of a product becomes the sum of the inverses, and the inverse of a sum becomes the product of the inverses ("break the bar, change the sign").
🗣️ Read it out loud
Say the meaning in words, then reveal it.
🎮 Name that law
Which law justifies each step?
🧩 Worked Example 19.01
Using the algebra to simplify an expression cannot be learned as a routine. It needs some lateral thinking.
Using Boolean algebra to simplify an expression: show that A + A.B can be simplified to A + B.
- First make it more complicated! The OR form of absorption says A + A.B = A. Use it in reverse to replace A by A + A.B: A + A.B + A.B
- Ignore the first A for the moment. The AND form of the commutative law and the OR form of the distributive law (in reverse) give: A.B + A.B = B.A + B.A = B.(A + A)
- The OR form of the inverse law turns A + A into 1. Bringing back the A: A + B.1
- The AND form of the identity law turns B.1 into B: A + B ✔
⚖️ Equivalence checker
Simplified something? Check it here: the checker builds a truth table for both expressions. Use letters for inputs, . (or nothing) for AND, + for OR, and ' after a letter or bracket (or ! before it) for NOT. Example: A + A'.B.
🧾 19.04 Creating an expression directly from a truth table
One formal approach is the sum-of-products method. You write a minterm for each row of the truth table whose output is 1, then OR the minterms together.
For the half adder (Table 19.01), only one row gives C = 1: A = 1 and B = 1. The product is A.B, and the sum of products has just this one term:
C = A.BTwo rows give S = 1, so its sum of products has two minterms:
S = A.B + A.BA 0 in a row is written as the inverse of that input.
Sometimes the laws can be applied straight to parts of the table. Suppose a truth table contains these two rows:
| A | B | C | X |
|---|---|---|---|
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
X is 1 whether C is 0 or 1, so there must be a minterm with no reference to C: A.B.
🛠️ Minterm builder
Tap the X column to set the outputs. The sum of products is written for you, followed by the simplest form (found the K-map way).
Sum of products:
Simplest form:
🎯 Practice: write the sum of products
Type a Boolean expression that matches the table (any correct form is accepted; then try for the simplest).
🔌 The Boolean algebra representation of a logic circuit
The same ideas can turn a circuit diagram into an expression: use the truth tables of the individual gates, then simplify with the algebra.
Creating a Boolean algebra logic expression for a half adder circuit
- A and B go into a NAND gate with output W. The first three rows of the NAND truth table give 1, so the sum of products has three minterms: W = A.B + A.B + A.B
- W and A go into a NAND gate to give X. Treat NAND as AND followed by NOT. The AND gives the product of the inputs: A.(A.B + A.B + A.B)
- The distributive and inverse laws simplify this: 0 + 0 + A.A.B, which is simply A.B
- Now apply the NOT, using the AND form of De Morgan's law, which turns A.B into A + B: X = A + B
- The same laws applied to the other intermediate NAND gate give: Y = A + B
- Finally A + B and A + B go into the last NAND gate. The AND part gives the product: (A + B).(A + B)
- Instead of multiplying it out, apply De Morgan's law directly to perform the inverse: S = A.B + A.B ✔This is exactly the expression we got from the truth table, so the algebra has been used correctly.
Show answer
C: both inputs of the last NAND gate are W, so C = W.W = W (idempotent). W = A.B, so C = A.B = A.B (double complement).
S, the long way: multiply out the product with the distributive law:
(A + B).(A + B) = A.A + A.B + B.A + B.B = A.B + A.B(A.A and B.B are 0 by the inverse law.) Now invert it with De Morgan's law twice:
S = A.B + A.B = (A + B).(A + B) = A.A + A.B + B.A + B.B = A.B + A.B🗺️ 19.05 Karnaugh maps (K-maps)
A Karnaugh map is a way of creating a Boolean expression from a truth table. It is usually much easier than writing minterms with sum of products and, used correctly, it gives the simplest possible expression.
| A | B | X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Table 19.06 The truth table for the OR operand
Sum of products gives:
X = A.B + A.B + A.BThat is not obviously A + B, although the algebra could show it. The K-map is simpler. Each cell holds the output X for one combination of A and B:
The rules for reading a K-map
- Only cells containing a 1 are considered.
- Groups of 1s are identified where possible; a group is a row, a column or a rectangle.
- Groups must contain 2, 4, 8 and so on cells.
- Each group should be as large as possible.
- Groups can overlap, and all overlapping groups must be used.
- If a cell cannot be put in any group, it is treated as a group on its own.
- Within each group, keep only the inputs whose value stays constant throughout the group.
In Figure 19.08 there is a column group and a row group. In the column, B stays the same but A changes, so B is kept. In the row, A stays the same. The expression is the sum of what is kept:
X = A + BThe K-map found the OR expression without any algebra.
🧩 Worked Example 19.03
Using a K-map to interpret a three-input problem
| A | B | C | X |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Table 19.07 A sample truth table with three inputs
Before using any method, look for trends. Whenever B = 1, X is 1, so the answer should be "B + something".
Sum of products gives five minterms:
A.B.C + A.B.C + A.B.C + A.B.C + A.B.CThere are two ways to lay out the K-map. Here the input values are combined in the columns: rows for A, columns for B and C.
The column labels do not follow binary order. They follow the Gray code sequence (00, 01, 11, 10), where only one bit changes each time.
The first group is the square of four 1s (blue rectangle). In it A changes and C changes, but B is constant, so only B is kept, as predicted.
That seems to leave the top-left cell, BC = 00, isolated. It is not, because K-maps wrap round. BC = 01 is next to it but holds a 0. Its other neighbour is BC = 10, at the far end of the row. So there is a row group of BC = 00 and BC = 10 (the dotted partial outlines). In it A stays the same, B changes and C stays the same, so the product is A.C. Adding the B from the other group:
A.C + BThat is much simpler than the five-minterm expression from the truth table.
🔬 K-map lab
Tap cells to set them to 1 or 0. The lab finds the largest groups (coloured dots show which groups each cell belongs to) and writes the simplest sum of products. The small number in each cell is its row number in the truth table.
Simplest expression:
🎯 Practice: simplify with a K-map
Draw the K-map on paper for this table, then type your simplified expression.
🧠 Extension Question 19.02
Show answer
- The 2 × 2 square in rows AB = 00, 01 and columns CD = 11, 10: A = 0 and C = 1 are constant: A.C.
- The overlapping 2 × 2 square in rows AB = 01, 11 and columns CD = 11, 10: B = 1 and C = 1: B.C.
- The top-left and bottom-left cells (AB = 00 and AB = 10, CD = 00) are a pair because the map wraps vertically: B = 0, C = 0, D = 0: B.C.D.
Load "Figure 19.10" into the K-map lab to see the groups.
📌 Summary
- Binary addition can be carried out using a half adder or a full adder circuit.
- SR or JK flip-flop circuits can be used to store a bit value.
- There are Boolean algebra laws that can be used to simplify logic expressions.
- The sum-of-products method can be used to create an equivalent logic expression containing minterms from a truth table.
- A Karnaugh map is a representation of a truth table that allows a simplified logic expression to be derived from it.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my mark-scheme-style points, not official mark schemes.
(i) OR, AND, NOT.
(ii) The top path is A + B; the AND gate gives A.B (which is also R); the NOT gives A.B; the final AND gives S.
| A | B | A + B | A.B | A.B | S | R |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 1 |
- It is a half adder.
- S is the sum bit (S = (A + B).A.B, which is XOR).
- R is the carry bit (R = A.B).
(i) X = A.B + A.B + A.B (one mark per minterm).
(ii) Whenever A = 1, X = 1 whatever B is, so the simplified expression will contain a term that is just A (A + …). The remaining 1 (A = 0, B = 0) is covered by B, giving X = A + B.
(i) A.B (the AND truth table is 1 only when both inputs are 1).
(ii) A + B. By sum of products: A.B + A.B + A.B, which simplifies to A + B.
(iii) A + B = A.B (OR form of De Morgan's law).
Teacher's note: the final gate gives X = A.B.A.B = 0, so this circuit always outputs 0. The question only asks about the intermediate outputs.
| B | B | |
|---|---|---|
| A | 1 | 0 |
| A | 1 | 1 |
(ii) Row group A = 1 gives A; column group B = 0 gives B. So X = A + B.
(i) X = A.B + A.B + A.B
(ii)
= A.B + A.B + A.B + A.B (idempotent, the hint) = B.(A + A) + A.(B + B) (distributive) = B.1 + A.1 (inverse) = A + B (identity, commutative)| A | B | X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
(i) Q = NAND(S, Q), Q = NAND(R, Q):
| S | R | Q | Q | |
|---|---|---|---|---|
| Initially | 1 | 0 | 0 | 1 |
| R changed to 1 | 1 | 1 | 0 | 1 |
| S changed to 0 | 0 | 1 | 1 | 0 |
| S changed to 1 | 1 | 1 | 1 | 0 |
| S and R changed to 0 | 0 | 0 | 1 | 1 |
(ii) S = 0 and R = 0. A NAND gate outputs 1 if any input is 0, so both Q and Q become 1. That breaks the rule that Q is the complement of Q, and when S and R return to 1 the final state depends on which input changes first, so it is unpredictable.
(c)(i) A clock (pulse) input.
(c)(ii) Any one: there is no invalid input combination (J = K = 1 toggles the output); the clock synchronises the inputs, so the circuit cannot enter an uncertain state.
(d) Each flip-flop stores one bit. Groups of flip-flops are used to build registers, static RAM (cache) and counters/shift registers.
Cambridge International AS & A Level Computer Science 9608, Paper 31 Q5, June 2016
In this half adder, output A is the AND (carry) and B is the XOR (sum). The first half adder gives P.Q and P⊕Q; the second gives (P⊕Q).R and P⊕Q⊕R; J ORs the two carries.
(i)
| P | Q | R | P.Q | P⊕Q | (P⊕Q).R | J | K |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 |
(ii) A full adder.
(iii) J = carry out (Cout) and K = sum (S). K is 1 when an odd number of P, Q, R are 1: the sum bit of adding three bits. J is 1 when two or more of the inputs are 1: the carry to the next column. R acts as the carry in from the previous column.
(i) X = A.((A + B).C)
(ii)
X = A.(A + B).C (associative) = (A.A + A.B).C (distributive) = (A + A.B).C (idempotent) = A.C (absorption)Or in one step: A.(A + B) = A by the AND form of absorption, so X = A.C.
Cambridge International AS & A Level Computer Science 9608, Paper 32 Q5, November 2016
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 19 Logic circuits and Boolean algebra · Figures from the Cambridge coursebook (Langfield & Duddell)