Transcript lecture02

Boolean Logic &
Number Systems
Today:
• Some Announcements
• First Hour: Introduction to Logic
– Section 1.2, 1.3 of Katz’s Textbook
– In-class Activity #1
• Second Hour: Number Systems
– Appendix A.1 and A.2 of Katz’s Textbook
– In-class Activity #2
1
Some Announcements
• An electronic copy of Katz’s textbook
is on the website!
• Wait-listed students can now login
– User name = ecse2610_stu
– Password = ecse2610_stu
2
Truth Tables
X
NOT X
0
1
1
0
X
Y
X AND Y
0
0
1
1
0
1
0
1
0
0
0
1
X
Y
X OR Y
0
0
1
1
0
1
0
1
0
1
1
1
Boolean
Equations
Gates
Inverter
Z=X
X
Z
AND
Z = X •Y = X Y
X
Y
Z
OR
Z= X+Y
X
Y
Z
3
Example Truth Tables
Half adder
A
0
0
1
1
adds two binary digits
to form Sum and Carry
Sum equals A plus B (modulo 2)
B
0
1
0
1
Sum Carry
0
0
1
0
1
0
0
1
Carry equals (A plus B minus Sum)/2
Full adder
adds two binary digits and
Carry in (Cin) to form Sum and
Carry Out (Cout)
Sum equals A plus B plus Cin (modulo 2)
Carry equals (A plus B plus Cin minus Sum)/2
A
0
0
0
0
1
1
1
1
B Cin Sum Cout
0 0
0
0
0 1
1
0
1 0
1
0
1 1
0
1
0 0
1
0
0 1
0
1
1 0
0
1
1 1
1
1
4
Truth Tables to Equations
Step 1: Identify each truth table row where the function value is 1
Step 2: Construct (ANDed) product terms of the inputs for these
rows
If input variable is 0, it appears in complemented form
If 1, it appears un-complemented
Step3: “OR” together these product terms
Half adder
A B Sum Carry
0
0
1
1
0
1
0
1
0
1
1
0
Sum = A B + A B
0
0
0
1
Carry = A B
5
Full Adder Example
A
B Cin
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Sum Cout
0
1
1
0
1
0
0
1
Sum = A B Cin + A B Cin + A B Cin + A B Cin
0
0
0
1
0
1
1
1
Cout = A B Cin + A B Cin + A B Cin + A B Cin
6
Equations to Truth Tables
Consider: Cout = A Cin + B Cin + A B
Fill in rest of
Cout with 0s
A
0
0
0
0
1
1
1
1
B Cin Cout
0 0
0
0 1
0
1 0
0
1 1
1
0 0
0
0 1
1
1 0
1
1 1
1
Put a 1 in each row
where product term
is true
Each product term in the
equation covers exactly two
rows in the truth table
Verify the equivalence of this Boolean equation:
compare this Cout with the original Cout truth table
Notice
This row is
covered 3 times
7
Equations to Circuits
Half Adder
Sum = A B + A B
A
A
AB
Sum
B
B
AB
Carry
AB
Carry = A B
8
Full Adder
Sum = A B Cin + A B Cin + A B Cin + A B Cin
\Cin \ B \ A
Cin B
A
A
Notation:
B
SUM
\A = A, etc.
Cin
Cout
Cout = A B Cin + A B Cin + A B Cin + A B Cin
9
Equivalent Circuits
\Cin \ B \ A
Cin B
A
A
B
SUM
Cin
Cout
A
B
B
Cin
Cout
A
Cin
Cout = A B Cin + A B Cin + A B Cin + A B Cin  Cout = A Cin + B Cin + A B
10
Some Practicalities
\Cin \ B \ A
Cin B
A
Fan-out
A
B
SUM
number of inputs
a gate output is
connected to
Cin
Fan-in
number of
inputs available
on a gate
Cout
A
B
B
Cin
Cout
A
Cin
"Rules of Composition" place limits on fan-in/fan-out
11
Do Activity #1 Now
• Reference:
–Section 1.2, 1.3 of Katz Textbook
12
Computers and Numbers
• Most modern computers use logic circuits that
exhibit two states (binary digital)
• Large binary numbers are unwieldy, so
alternative representations are used.
• Hexadecimal numbers are a compromise
between efficient representation and conversion
to a more natural (to most humans) decimal
system.
• It is important to understand these other bases
when designing hardware and software.
13
Notation
• Unless otherwise noted, the default base for
quantities is decimal (base 10)
• Subscripts following a quantity indicate the base
• Examples:
12310 is base 10 or decimal, so is 123
12316 is base 16 or hexadecimal
1012 is base 2 or binary
• Other notation (used later on in this course):
%101 is binary
$123 is hexadecimal
14
Decimal Numbers
Uses 10 digits [ 0, 1, 2, . . . 9 ]
Positional Number Notation
Weight of digit determined by its position.
Example:
246
= 200 + 40 + 6
= 2 x 102 + 4 x 101 + 6 x 100
In general:
N =  Ni x 10i where Ni  [0, 1, 2, . . .8, 9],
where Ni are the weights and the base of the number
system is raised to the exponent i.
Note: decimal fractions occur when i is negative
0.35 = 3 x 10-1 + 5 x 10-2
15
Binary Numbers
Uses 2 digits [ 0 & 1 ]
Positional Number Notation
Example:
1110012
= 1000002 + 100002 + 10002 + 0002 + 002 + 12
= 1 x 25 + 1 x 24 + 1 x 23 + 0 x 22 + 0 x 21 + 1 x 20
= 1 x 32 + 1 x 16 + 1 x 8 + 0 x 4 + 0 x 2 + 1 x 1
= 5710
In general:
N =  Ni x 2i where Ni  [0, 1].
Note: binary fractions occur when i is negative
0.112 = 1x 2-1 + 1 x 2-2 = 0.510 + 0.2510 = 0.7510
16
Hexadecimal (Hex) Numbers
Uses 16 digits [ 0, 1, 2, . . . 9, A, B, C, D, E, F ]
Positional Number Notation
Note: A - F represent the decimal values of 10 - 15, respectively.
Example:
89AB16 = 800016 + 90016 + A016 + B16
= 8 x 163 + 9 x 162 + A x 161 + B x 160
= 8 x 4096 + 9 x 256 + 10 x 16 + 11 x 1 = 3524310
In general:
N =  Ni x 16i where Ni  [0, 1, 2, ..., 9, A, B, C, D, E, F].
Note: hexadecimal fractions occur when i is negative
0.9A16 = 9 x 16-1 + 10 x 16-2 = 0.562510 + 0.039062510 = 0.601562510
17
Conversion Among Bases
Conversion from any base to decimal:
Use positions and weights !
Eg: Decimal value =  Ni x Bi where Ni  [0, 1, 2, . . . NB-1]
(  means “sum of”)
Eg: 89AB16= 8 x 4096 + 9 x 256 + 10 x 16 + 11 x 1 = 3524310
Conversion among the 2n bases (binary, hexadecimal, octal,
etc.):
First convert to binary (base 2) & then regroup into n bits
Then convert the groups of bits into the proper digits.
18
Hexadecimal  Binary
Example: convert 100110001110011012  hexadecimal
Group by 4s, starting at the right  expand into 4 bit groups
1 0011 0001 1100 11012  1 3 1 C D16
Memorize
this table!!!
It makes
conversions
between
hexadecimal
and binary
trivial
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Binary Decimal
0000
0
0001
1
0010
2
0011
3
0100
4
0101
5
0110
6
0111
7
1000
8
1001
9
1010
10
1011
11
1100
12
1101
13
1110
14
1111
15
19
Decimal  Binary
Successive Division: an easy way to convert Decimal to Binary
Based on the remainders after dividing the decimal number repeatedly
by 2.
If the decimal number is even, the corresponding binary number will end
in a 0, and if it is odd, the binary number will end in a 1, and so on.
Example:
57 / 2 = 28,
28 / 2 = 14,
14 / 2 = 7,
7 / 2 = 3,
3 / 2 = 1,
1 / 2 = 0,
remainder
remainder
remainder
remainder
remainder
remainder
= 1 (binary number will end with 1)
=0
=0
=1
=1
= 1 (binary number will start with 1)
Therefore, collecting the remainders, 5710 = 1110012
(((((0x2 + 1)x2 + 1)x2 + 1)x2 +0)x2 +0)x2 +1 = 1x32 + 1x16 + 1x8 + 0x4 + 0x2 + 1x1 = 57
(check: 32 + 16 + 8 + 0 + 0 + 1 = 57)
20
Decimal  Hex
Successive Division: an easy way to convert Decimal to Hexadecimal
Based on the remainders after dividing the decimal number by higher
powers of 16.
Example:
35243 / 16 =
2202 / 16 =
137 / 16 =
8 / 16 =
2202,
137,
8,
0,
remainder = 11  B (hex number will end with B)
remainder = 10  A
remainder = 9
remainder = 8
(hex number will start with 8)
Therefore, collecting the remainders, 3524310 = 89AB16
(check: 8 x 4096 + 9 x 256 +10 x 16 + 11 = 35243)
Notice how simple this method is
21
Hex  Decimal
Multiplication: an easy way to convert Hexadecimal to Decimal
Multiply the hexadecimal weights by powers of 16.
Example:
BA89  B x 163 + A x 162 + 8 x 16 + 9
(CAUTION: mixed bases)
= 11 x 4096 + 10 x 256 + 8 x 16 + 9
= 45056 + 2560 + 128 + 9
= 47753
We can check by converting back to hex:
47753 / 16 = 2984 + remainder, 9
2984 / 16 = 186 + remainder, 8
186 / 16 = 11 + remainder, 10  A
11 / 16 = 0 + remainder, 11  B
 4775310  BA8916
22
Binary  Decimal
Multiplication: an easy way to convert Binary to Decimal
We can multiple the binary weights by powers of 2.
However, sometimes it is just as easy to convert the binary
number to hexadecimal first and and then into decimal.
Compare:
110101102  27 + 26 + 24 + 22 + 2 (exploiting the binary weights)
= 128 + 64 + 16 + 4 + 2
= 21410
110101102  D616  13 x 16 + 6 = 208 + 6 = 21410
23
Do Activity #2 Now
Due: End of Class Today
RETAIN THE LAST PAGE (#3)!!
For Next Class:
• Bring Randy Katz Textbook
– Course website has an electronic copy available.
• Required Reading:
– Sec A.1, A.2, 2.1, 2.2 (up to 2.2.4) of Katz
• This reading is necessary for getting
points in the Studio Activity!
• Studio Session #2 Tuesday/Wednesday
24