☰ Year plan · Communication Technology

The parts of a computer

Week 6 · Chapter 7 Computers: computer configuration, the five units, software, logic circuits and the half adder · 3 lessons
3

Logic gates: how a circuit adds two bits

ICT Secondary 1 Term 1, Chapter 7: pp. 85–94
GoalRead the truth tables of AND, OR, NOT and XOR, and explain how two gates add two bits.
New words
logic circuit · a circuit built from gates that work on 0 and 1truth table · a table of all inputs and the output of eachXOR · true when exactly one of the two inputs is 1half adder · a circuit that adds two bits and gives a sum and a carry
Explanation

A logic gate takes bits as inputs and gives one bit. AND gives 1 only if both inputs are 1: a door opens only if the card is valid AND the code is right. OR gives 1 if at least one input is 1: an alarm rings if there is smoke OR heat. NOT flips its single input: 0 becomes 1 and 1 becomes 0. XOR gives 1 if exactly one input is 1: a staircase light that two switches control is on when the switches are in different positions. A truth table lists every input and the output. A half adder adds two bits A and B. Check the four cases: 0 + 0 = 00, 0 + 1 = 01, 1 + 0 = 01 and 1 + 1 = 10 in binary. The right bit, the sum, is 1 exactly when one input is 1, so sum = A XOR B. The left bit, the carry, is 1 only when both are 1, so carry = A AND B. Two half adders and an OR gate make a full adder, which also takes a carry from the column on the right; chains of full adders add whole numbers inside the processor. Note that XOR can be built from AND, OR and NOT, but it is a gate of its own.

ABA∧BA∨BA⊕B
00000
01011
10011
11110
Worked examples
ABA⊕BA∧B
0000
0110
1010
1101
The picture above shows AND (∧), OR (∨) and XOR (⊕) for every pair of inputs. Now the half adder: the sum column is the XOR and the carry column is the AND. For 1 + 1 the sum is 0 and the carry is 1, which together read 10, the binary number two.
smokeheatsilencedalarmsiren
10110
10011
00000
NOT flips a bit. A small circuit: “alarm = smoke OR heat” and “siren = alarm AND NOT silenced”. If smoke = 1, heat = 0 and silenced = 1, then alarm = 1 and NOT silenced = 0, so siren = 1 AND 0 = 0.
Class activity

On paper, make the truth table for the invented rule “the garden light is on if it is dark AND someone is near”. Then find two input rows where the light is off although one input is 1.

Practice
1
What does OR give when A = 0 and B = 1?
2
What does XOR give when A = 0 and B = 0?
3
Add the bits 0 + 1 with a half adder. What are the sum and the carry?
4
Which gate flips its input?