0% found this document useful (0 votes)
23 views

Counting using logic gates

The document discusses the foundations of computational thinking and programming, focusing on logic gates, half-adders, and full adders used in binary arithmetic. It highlights the limitations of Boolean algebra and provides exercises for drawing logic circuits based on Boolean expressions. Additionally, it explains how processors perform arithmetic operations using logic gates and the significance of clock speeds in regulating these processes.

Uploaded by

Alistair Frame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Counting using logic gates

The document discusses the foundations of computational thinking and programming, focusing on logic gates, half-adders, and full adders used in binary arithmetic. It highlights the limitations of Boolean algebra and provides exercises for drawing logic circuits based on Boolean expressions. Additionally, it explains how processors perform arithmetic operations using logic gates and the significance of clock speeds in regulating these processes.

Uploaded by

Alistair Frame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

FOUNDATIONS

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)

for the following


Boolean expressions:
b)
a) Q = A ⊻ B ∨ ¬B
b) Q = ¬A ∧ B ∨ C
c) Q = ¬(A ∨ B) ∨ (A ∧ C)
c)
Learning outcomes

1. We will see how logic gates are used to perform


binary arithmetic we studied earlier in the term
2. We will explore two new concepts: half-adders and
full adders
3. We will see how half-adders and full adders are
used to do binary arithmetic
How a processor does Maths using
logic gates
• A CPU consists of transistors which regulate
electrical signals
• An open transistor through which no current is
flowing represents 0 Open (off)
• A closed transistor, through which a current is
flowing represents 1
• The pulses of electricity that pass through
transistors are regulated by the computer’s clock
• From this we can conclude that the computer’s
clock (located in the CPU), regulates how fast the Closed (on)
computer works
• Clock speeds are measured in megahertz or
millions of ticks per second
How a processor does Maths using
logic gates
• We learned in previous lessons that current
passing through one transistor can control
another transistor (example: revision
exercise at the start of this session) Open (off)
• We also learned that there are different
types of logic gates and they all control the
electrical current differently
• With different combinations of logic gates, a
computer performs the maths that is the Closed (on)
foundation of its operations.
• This is done using half-adders and full-
adders
A B
1
1
+1
+1
decimal
binary
Half-adder
• A half-adder is a
combination of an XOR gate
and an AND gate
• Both of which receive the
same input representing a
AND XOR
one-digit binary number
• If the inputs above are 1s
C S what will be the outputs in C
? ? Binary and S?
Decimal = ?
A B
1
1
+1
+1
decimal
binary Half-adder
• If the inputs above are 1s
what will be the outputs in Q
and P?
• The output in binary
would be 10 and in
AND XOR
decimal 2

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

0A3 0A2 1A1 1A0 3 C4 1-bit C3 1-bit C2 1-bit C1 1-bit C0


full full full full
+ 1B3 0B2 1B1 1B0 11 adder adder adder adder
= 1S3 1S2 1S1 0S0 14
S3 S2 S1 S0
Connecting full adders
• What would be the output
A3 B3 A2 B2 A1 B1 A0 B0
from a fifth adder connected
to the diagram on the left if
the inputs for A4 and B4 C4 1-bit C3 1-bit C2 1-bit C1 1-bit C0
full full full full
were 0 and 1? What would adder adder adder adder
be the output C5?
S3 S2 S1 S0
Connecting full adders
• What would be the output
A3 B3 A2 B2 A1 B1 A0 B0
from a fifth adder connected
to the diagram on the left if
the inputs for A4 and B4 C4 1-bit C3 1-bit C2 1-bit C1 1-bit C0
full full full full
were 0 and 1? What would adder adder adder adder
be the output C5?
S3 S1 S0
Answer: S4 = 1, C5 = 0 S2
Learning outcomes
1. Today you explored how logic gates are used to
perform binary arithmetic we studied earlier in the
term
2. We looked at two new concepts: half-adders and full
adders
3. We investigated how half-adders and full adders are
used to do binary arithmetic
Revising ideas from today

1. How does a full adder differ A B S C


from a half-adder? - give at
least 2 examples
2. Complete the truth table on
the left for a half-adder’s
outputs S and C
Revising ideas from today
1. How does a full adder differ A B S C
from a half-adder? - Half-
adder does not take a 0 0 0 0
carry bit as input and a
full adder does. A full 0 1 1 0
adder combines one or
1 0 1 0
more half adders and
other switches 1 1 0 1
2. Complete the truth table on
the left for a half-adder’s
outputs S and C

You might also like