A levels Computer Science · Computer systems
Boolean algebra and logic gates
1Logic gates and truth tables
A logic gate takes one or more binary inputs and gives a binary output.
| A | B | NOT A | A AND B | A OR B | A XOR B | A NAND B | A NOR B |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
Notation: NOT A is written ¬A or Ā; A AND B as A·B or A ∧ B; A OR B as A + B or A ∨ B; XOR as A ⊕ B.
NAND and NOR are universal gates: any circuit can be built from NAND gates alone.
Check yourself
What is the output of NAND when both inputs are 1?
Show the answer
0
NOT (1 AND 1).
2Circuits and Boolean expressions
A logic circuit combines gates. Each circuit can be written as a Boolean expression.
Q = (A AND B) OR (NOT C)
- Work out the inner parts first, column by column.
- For A = 1, B = 0, C = 0: A·B = 0, ¬C = 1, so Q = 0 + 1 = 1.
- A full truth table for 3 inputs needs 2³ = 8 rows.
| A | B | C | A·B | ¬C | Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 1 |
(Only three of the eight rows are shown.)
Check yourself
How many rows does the truth table for 4 inputs need?
Show the answer
16
2⁴.
3Boolean laws
| Law | AND form | OR form |
|---|---|---|
| identity | A·1 = A | A + 0 = A |
| null | A·0 = 0 | A + 1 = 1 |
| idempotent | A·A = A | A + A = A |
| complement | A·¬A = 0 | A + ¬A = 1 |
| double negation | ¬¬A = A | |
| absorption | A·(A + B) = A | A + A·B = A |
| distributive | A·(B + C) = A·B + A·C | A + B·C = (A + B)·(A + C) |
| De Morgan | ¬(A·B) = ¬A + ¬B | ¬(A + B) = ¬A·¬B |
De Morgan's laws: "break the bar and change the sign".
Check yourself
What is ¬(A + B) by De Morgan's law?
Show the answer
¬A · ¬B
Break the bar, change OR to AND.
4Simplifying expressions
Simplify A·B + A·¬B
- Take out the common factor A: A·(B + ¬B).
- B + ¬B = 1 (complement law).
- A·1 = A (identity law).
Simplify ¬(¬A + B)
- De Morgan: ¬¬A · ¬B.
- Double negation: A·¬B.
Simplify (A + B)·(A + ¬B)
- Expand: A·A + A·¬B + B·A + B·¬B.
- A·A = A and B·¬B = 0: A + A·¬B + A·B.
- Absorption: A + (anything AND A) = A.
Simpler expressions need fewer gates, so circuits are cheaper, smaller and faster.
Check yourself
What does A + A·B simplify to?
Show the answer
A
Absorption.
5Adders
A half adder adds two bits, giving a sum and a carry.
A half adder. The XOR gate gives the sum bit and the AND gate gives the carry bit.
| A | B | Sum (A ⊕ B) | Carry (A·B) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
A full adder also adds a carry in from the previous column:
- Sum = A ⊕ B ⊕ C_in
- C_out = A·B + C_in·(A ⊕ B)
Chaining full adders, each carry out feeding the next carry in, adds whole binary numbers.
Check yourself
What are the outputs of a half adder for A = 1, B = 1?
Show the answer
Sum 0, carry 1
1 + 1 = 10 in binary.
6Flip-flops and Karnaugh maps
A D-type flip-flop stores one bit. On each rising edge of the clock signal, its output Q takes the value of the data input D, then holds it until the next clock edge. Flip-flops are used to build registers and memory.
A Karnaugh map is a grid used to simplify expressions. Cells with 1 are grouped in rectangles of 1, 2, 4 or 8; each group gives one simple term.
A 2-variable map for ¬A·B + A·¬B + A·B
- Put 1s in the cells for (A, B) = (0, 1), (1, 0) and (1, 1).
- The two 1s with A = 1 form a group: A.
- The two 1s with B = 1 form a group: B.
- Result: A + B.
| B = 0 | B = 1 | |
|---|---|---|
| A = 0 | 0 | 1 |
| A = 1 | 1 | 1 |
Check yourself
What does a D-type flip-flop store?
Show the answer
One bit, updated on the clock edge
Basis of registers.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera