Lect-3 Digital Age - The Power of 0 and 1
Lect-3 Digital Age - The Power of 0 and 1
1
The Digital Age
• Today’s information age is characterized by the pervasive processing of
information as discrete numbers (digitization), by transistor-based electronics.
• Often, we hear the terms “digital age ” and “electronic age” used almost
synonymously as “information age”.
• Today, most electronic computing systems are binary based – they process
discrete numbers using two digits only – 0 and 1
• In this lecture, we want to understand:
❑ Binary logic as one of the scientific foundations of the IT revolution
❑ Implementing logic and computation by switching circuits/logic gates
• Reference: Chapter 2 of Text: The Hardware
P.2
I. Leibniz’s Binary Number
• Gottfried Leibniz (1646-1716) was a German polymath and
philosopher
- It is disputed whether he or Newton first invented calculus
- Inventor of the Leibniz wheel
• In 1679, in his book The Dyadic System of Numbers, Leibniz
introduced the concept of binary numbers based on two digits
only. He showed how we can do computation using binary
numbers instead of decimal numbers
• Leibniz thought there is something divine in binary numbers.
• On a coin is Leibniz’s statement: “One is sufficient to create
everything out of nothing.”
P.3
Recording Numbers in Binary
• Our familiar decimal numbering system has 10 digits (0 – 9) and is
based on powers of 10.
For example, the number 238 means:
8 + 3 x 101 + 2 x 102 = 8 + 30 + 200 = 238
The majority of ancient
civilizations had a 10-digit
• The binary number system has 2 digits (0 and 1) only and is based numbering systems most likely
on powers of 2. because we have 10 fingers
The binary equivalent of decimal 238 is 11101110 since:
0 + 1 x 2 1 + 1 x 22 + 1 x 2 3 + 0 x 2 4 + 1 x 25 + 1 x 2 6 + 1 x 2 7
= 0 + 2 + 4 + 8 + 0 + 32 + 64 + 128 = 238
11101110
+128+64 +32 +8 +4 +2
P.4
Converting a Decimal Number to Binary
• To convert a decimal number to binary, we can keep dividing by 2 and record
the remainders from last to first as most significant to the least significant.
Example: What is the decimal 371 in binary?
least significant digit
2)371 1
2)185 1
2)92 0
2)46 0
2)23 1
2)11 1
2)5 1
2)2 0
most significant digit 1
• The resulting binary number is: 371 = 1 0 1 1 1 0 0 1 1
+256 +64 +16 +2 +1
+32
5
Computation by Binary Numbers - Addition
• We can add binary numbers like we add decimal numbers
609 1001100001
Carry=1
Carry
P.6
Computation by Binary Numbers -Multiplication
• We can multiply two binary numbers very efficiently using simple shifting and addition.
Example:
29 Operand A 11101 29 decimal=111001 binary
58 00000
Shift Operand A and
+ 29 Shift by 1 00000 multiply by corresponding
bit of Operand B
11101
348
+ 11101
10 1 0 11 100 = 348 decimal
• While it is cumbersome for human to write down long strings of “1”s and “0”s to record
binary numbers, we will see that it is much simpler for machines to handle binary numbers.
P.7
ENGG1150 Lecture 3
8
II. Boole’s Logic
• All higher level human reasoning are based on languages made up of discrete symbols and
signs, and through discrete steps of thoughts.
• George Boole (1815-64), an English mathematician and philosopher, in his book An
Investigation of the Laws of Thought, sought to develop a mathematical language for
modeling human reasoning.
• Boole recognized that all languages and reasoning logic can be reduced to two elementary
symbols/values (true and false) and a small set of elementary operations (NOT, AND, OR).
Two symbols is sufficient because we can represent any symbol in any language by a longer
string of the two symbols.
• At the time, Boole’s theory did not appear to be of much use. But by the end of the 19th
century, what is now known as Boolean algebra has become one of the foundations for
symbolic mathematics and epistemology.
P.9
Boole’s Basic Logic Operations: NOT, AND, OR
P.10
The NOT Gate - Modern Description
• It is the simplest operation with one input 𝐴 and one output 𝐵
• Output is the opposite logic value of input: When 𝐴 = “1/true”, 𝐵 = “0/false”.
When 𝐴 = “0/false”, 𝐵 = “1/true”
1. Gate Symbol
2. Boolean Expression:
Standard 𝐴 𝐵 Pronounced commonly
𝐵 = 𝐴ҧ as “A bar”, “A not”, or
“not A”
Abbreviated 𝐵
𝐴
3.Truth Table
𝐴 𝐵 Truth Table
- A table that lists the outputs for all
1 0 combinations of the inputs
0 1
P.11
The AND Gate
• Two inputs (𝐴,𝐵) and One output (𝐶)
• Output is true only when both inputs are true:
When 𝐴 = 𝐵 = “1” , 𝐶 = “1”; otherwise 𝐶 =“0”.
Gate Symbol Boolean Expression
𝐴 Pronounced
𝐶 𝐶 = 𝐴 ∙ 𝐵 or simply 𝐶 = 𝐴𝐵 “𝐶 equals 𝐴 and 𝐵”
𝐵
Truth Table
𝐴 𝐵 𝐶
0 0 0
0 1 0
1 0 0
1 1 1
P.12
The OR Gate
• Two inputs (𝐴,𝐵), One output (𝐶)
• Output is true if at least one of the two inputs is true: When 𝐴
or 𝐵 = “1” , 𝐶 = “1”. 𝐶 =“0” only when 𝐴=𝐵=“0”
Gate Symbol Boolean Expression:
𝐴 Pronounced
𝐶 𝐶 =𝐴+𝐵 “C equals A or B”
𝐵
Truth Table
𝐴 𝐵 𝐶
0 0 0
• In a Boolean expression, we assume
“AND” takes precedent before “OR”, so
0 1 1
1 0 1 𝐴 + 𝐵 ∙ 𝐶 means 𝐴 + (𝐵 ∙ 𝐶)
1 1 1
P.13
ENGG1150 Lecture 3
14
III. Shannon’s Logic Circuits An old dial-pulse Electromechanical
stepping relays for
phone
telephone switching
• In the 1930’s, automatic electromechanical telephone
switching systems based on stepping relays were widely
deployed, and so were mechanical arithmetic machines and
cash registers.
• But there were no general theory for systematic construction
of switching and arithmetic functions using electrical circuits.
• Then came Claude Shannon’s (1916-2001) first revolutionary
idea: the linking of switching circuits to Boolean algebra in his
1938 master thesis at MIT.
• Shannon graduated from U. Michigan in 1936 and was hired
to work on the differential analyzer. He was asked to study Shannon’s second
how a network of switches (or relays) can be arranged so that revolutionary idea is
his information
the analyzer can be easily reconfigured to solve different theory in 1948,
differential equations. discussed in a later
lecture.
P.15
Switches as Logic Gates
• Shannon recognized that one could use the open/close state of a switch which
hinder/allow a current flow to represent the binary values 1/0 or true/false.
• In his original thesis, he defined an open switch, where current cannot flow, as having
the logic value 1 (hindrance is “on”)
P.16
Switches as Logic Gates
Then
• Two switches in parallel form a logic AND, while two switches in series form a logic OR
• A switch that is thrown to left or right forms an 𝐴/𝐴ҧ logic value pair.
AND Gate OR Gate NOT Gate
𝐴
𝐴 𝐵
𝐴 𝐴
𝐵
𝐴∙𝐵 𝐴+𝐵
Switch thrown to
Current hindered only when Current hindered if
open left or right
both A and B are open any of A, B is open
P.17
Network of Switches and Logic Expression
• We can implement any Boolean logic expression using a network of switches in series-
parallel form. Example:
𝑋𝑎𝑏 = (𝑅 + 𝑆) ∙ ( 𝑅 + 𝑇 ∙ 𝑈 + 𝑇+𝑆 ∙𝑉 )
A Series-Parallel Network 𝑅 𝑆
𝑎 𝑏
𝑅 𝑇 𝑇 𝑆
𝑈 𝑉
P.18
Example – A 3-bit Comparator
• Say we want to build a comparator which determines if two 3-bit binary numbers
A=𝐴1𝐴2𝐴3 and 𝐁 = 𝐵1𝐵2𝐵3 are equal.
• The Boolean expression is
(𝐴1 𝐵1 + 𝐴1ҧ 𝐵ത1 )∙ (𝐴2 𝐵2 + 𝐴ҧ2 𝐵ത2 ) ∙ (𝐴3 𝐵3 + 𝐴ҧ3 𝐵ത3 )
𝐴1 𝐴1ҧ
𝐵2 𝐵ത2
𝐴3 𝐴ҧ3
𝐵3 𝐵ത3
P.19
Simple Arithmetic with Logic Gates
• The simplest arithmetic logic unit is the 1-bit Half Adder, which adds two single digit binary
numbers (bits) together to produce two output bits: a SUM and a CARRY bit
The contraction word “bit” for “binary digit” actually was not introduced until 1948 by Shannon. We will
explain why we call this a half-adder later
Truth Table
𝐴 𝐵 𝐴 𝐵 𝐶 𝑆𝑢𝑚
𝐴 0 0 0 0
𝐶 ҧ + 𝐴𝐵;
𝑆𝑢𝑚 = 𝐴𝐵 ത
+ 𝐵 HA
0 1 0 1
𝐶 𝑆𝑢𝑚
𝑆𝑢𝑚 1 0 0 1
𝐶 = 𝐴𝐵
1 1 1 0
We can write down the Boolean expression for the SUM digit and CARRY digit by
OR’ing together every “1” entry in the output column of the truth table.
A. K. Wong P.20
1-bit Half Adder Circuit Diagram
From the truth table or logic formula, we can map the 1-bit half adder to a
circuit implementation, using modern logic gate symbols instead of
Shannon’s network of switches, as shown below:
𝐴ҧ
ҧ
𝐴𝐵
A
𝐵
ҧ + 𝐴𝐵ത
𝑆𝑢𝑚 = 𝐴𝐵
𝐵ത
B 𝐴𝐵ത
𝐴
𝐶 = 𝐴𝐵
𝐵
A. K. Wong P.21
1-bit Full Adder and Multiple Bit Adders
• The 1-bit full adder has an additional CARRY input bit so that we can cascade them
to build adders for multiple-bits binary numbers.
Truth Table
𝐴 𝐵 𝐶𝑖𝑛 𝐶𝑜𝑢𝑡 𝑆𝑢𝑚
0 0 0 0 0
𝐴 𝐵 Boolean Expression:
𝐴 0 0 1 0 1
Cout C C C
A 4-Bit Full Adder FA FA FA FA Cin
3 2 1
S4 S3 S2 S1
P.22
Another Example – 7-Segment LED Digit Display
• Below is the truth table for a 7-segment LED (Light Emitting Diode) digit display.
Many electronic
factories in Hong Kong
a made their wealth in
f b the 1970s and 80s by
g making these
e c
d
• A Boolean expression for display segment “a”, by OR’ing together all “1” entries
without simplication, is:
𝐴ҧ𝐵ത 𝐶ҧ 𝐷
ഥ + 𝐴ҧ𝐵𝐶
ത 𝐷ഥ + 𝐴ҧ𝐵𝐶𝐷
ത ҧ 𝐶𝐷
+ 𝐴𝐵 ҧ + 𝐴𝐵𝐶
ҧ 𝐷 ҧ
ഥ + 𝐴𝐵𝐶𝐷 + 𝐴𝐵ത 𝐶ҧ 𝐷 ҧ
ഥ + 𝐴𝐵ത 𝐶𝐷
• What is the logic expression for segment “e” as a function of the four inputs?
P.23
ENGG1150 Lecture 3
24
IV. von Neumann’s Fetch-Execution Cycle
• What we have seen so far are “combinational circuits”, in which the outputs are
determined by “combinations” of the input values.
• We often need “sequential circuits”, in which the output evolves over time (e.g., counter )
or where it takes multiple steps to arrive at the answer (doing division, square root, etc.)
• A flip-flop is a simple 1-bit memory device. It is a logic circuit that uses feedback of output
to the input to create hysteresis – a state that is unchanged until reset.
Truth Table and Circuit Diagram for a Flip-Flop
Truth Table for NOR Gate
Reset “NOT OR” =NOR Gate
𝐴 𝐵 𝐴 𝑁𝑂𝑅 𝐵
Once Q is set to 1 by S, 0 0 1
it stays unchanged until
it is cleared to 0 by R 0 1 0
1 0 0
Set
1 1 0
Indeterminate
A. K. Wong P.25
Clocked Flip-Flop and The Register
• In a clocked flip-flop, the R and S inputs of a flip-flop are AND’ed with a “Clock” signal so
that set/reset is enabled only when the “Clock” is on.
• In our computers and logic circuits, most logic gates are controlled by a common clock so
that all state changes are synchronized. (For example, the 7-segment display would flicker
if updates of the A, B, C, D inputs are not synchronized).
• A “register” is multiple clocked flip-flops in parallel to hold multiple bits.
Set
A 4-bit Register
Reset
P.26
A. K. Wong
The Fetch Execution Cycle
• Registers hold the data and instructions for the “fetch-execution cycle” in the von Neumann
architecture described in Lecture 2. In a modern computer, during each clock cycle:
- Control Unit fetches next instruction and needed data and hold them in registers
- Arithmetic Unit executes logic on data according to instruction and makes sure output is
ready before next clock cycle.
- At next clock tick, send results back to memory and repeat cycle
• Modern computers typically have a memory hierarchy where data/results not immediately
needed are kept in slower but cheaper “secondary memory”.
• All modern processors are based
on the fetch-execution cycle computation
model. The model represents a Turing
machine that is theoretically capable of
solving all solvable problems.
A. K. Wong P.27