Counting using logic gates
Counting using logic gates
OF
COMPUTATIONAL
THINKING AND PROGRAMMING
Counting using logic gates
Revising ideas from the previous
lesson
1. What is one limitation of Boolean algebra as covered in the
previous session?
2. Draw three logic circuits for the following Boolean
expressions:
a) Q = A ⊻ B ∨ ¬B
b) Q = ¬A ∧ B ∨ C
c) Q = ¬(A ∨ B) ∨ (A ∧ C)
Revising ideas from the previous
lesson
1. Boolean algebra does not contain a representation ‘for all A’
or ‘for all B’. A condition in Boolean algebra is needed to
qualify A or B.
2. Draw three logic circuits for the following Boolean
expressions:
a) Q = A ⊻ B ∨ ¬B
b) Q = ¬A ∧ B ∨ C
c) Q = ¬(A ∨ B) ∨ (A ∧ C)
Revising ideas from the previous
lesson
2. Draw three logic circuits a)
C S
1 0 Binary
Decimal = 2
A B
1
1
+1
+1
decimal
binary Half-adder
• A half-adder has only 2 inputs
and 2 outputs
• One of these outputs is the
Sum of the calculation (S)
and the other is the carry bit
AND XOR
(C)
• Represent S and C as Boolean
C S expressions
1 0 Binary
Decimal = 2
A B
1
1
+1
+1
decimal
binary Half-adder
• Represent S and C as Boolean
expressions
S=A⊻B
C=A∧B
The name ‘half-adder’ comes
AND XOR from the fact that it does not
have a carry bit as input
C S
1 0 Binary
Decimal = 2
Cin B A
Full adder
• A full adder consists of two half adders
and other switchers
• A full adder takes two inputs: A and B
and a carry bit C
• A combination of a half-adder and a full
adder can handle larger binary
numbers and generate results that
involve carrying over numbers
• With the right combination of gates, it is
possible to output the result of a binary
addition or subtraction including the
Cout S value of any carry bit as a second input
Cin B A
Full adder
• The Boolean expression for the full
adder on the left is as follows:
S = A ⊻ B ⊻ Cin
Cout = (A ∧ B) ∨ (Cin ∧ (A ⊻ B))
Cout S
Cin B A
Full adder
Complete the truth table for S and
Cout the full adder below:
A B Cin S Cout
0 + 0 + 0 = ? ?
0 + 0 + 1 = ? ?
0 + 1 + 0 = ? ?
0 + 1 + 1 = ? ?
1 + 0 + 0 = ? ?
1 + 0 + 1 = ? ?
1 + 1 + 0 = ? ?
Cout S 1 + 1 + 1 =
Cin B A
Full adder
Answers to the truth table task
below:
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
Cout S 1 + 1 + 1 = 1 1
Connecting full adders
• Multiple full adders could be connected together
• Using this construct, n full adders can be connected together in order
to input the carry bit into the next adder along with new inputs
• The four-bit adder below is an example of a standard component that
can be used in many applications involving arithmetic operations
A3 B3 A2 B2 A1 B1 A0 B0
0C3
1C2
1C1