Professional Documents
Culture Documents
ECE 238L – 2
Computer Logic Design
Authors:
Richard S. Sandige
Michael L. Sandige
Website:
http://www.mhhe.com/sandige
1
8/27/15
Binary Codes
2
8/27/15
Logarithms
• In general: logB A = x is equivalent to A = Bx
– log2 8 = 3 since 8 = 23
– log5 1/5 = -1 since 1/5 = 5-1
– log81 3 = 1/4 since 3 = 811/4
• Properties:
– logB (ab) = logB a + logB b
– logB (a/b) = logB a - logB b
– logB (ap) = p logB a
– logB (a1/r) = 1/r logB a
– logA (B) logB (C) = logA (C)
• ln B logB C = ln C
• logA B logB A = 1
Binary Codes
• How many distinct elements can we represent with n
bits?
– N = 2n
– n-bit code is found by counting in binary from 0 to (2n – 1)
• We can let a set of bits represent distinct elements
by a CODE (language)
• EX: wish to find a binary code to represent the ten
decimal numbers (0,1,2,3,4,5,6,7,8,9)
– Have 10 distinct elements
– Need log2 N = n (number of binary digits) Ceiling Function
– Need four bits minimum: 24 = 16 > 10 elements; n = 4
• 10 symbols with meaning or CODE are used
• 6 symbols are extra; not used
3
8/27/15
Powers of 2n
Base
Power
Result
Denomina2on
2
1
2
2
4
3
8
4
16
5
32
6
64
7
128
8
256
9
512
10
1024
KILO
11
2048
12
4096
13
8192
14
16384
15
32768
16
65536
17
131072
18
262144
19
524288
20
1048576
MEGA
30
1073741824
GIGA
1073741824
1.09951E+12
40
1.09951E+12
TERA
4
8/27/15
Binary Codes
• EX: wish to find a binary code to represent
1009 different objects
– Have 1009 distinct elements
– Need log2 N = n (number of binary digits) Ceiling
Function
– Need ten bits minimum: 210 = 1024 > 1009
elements; n = 10
• 1009 symbols with meaning or CODE are used
• 15 symbols are extra; not used
Binary Codes
• EX: wish to find a binary code to represent
20,234,567 different objects. Only have log10
or ln functions
– Make C = 20,234,567; B =2; A =10
– Using: ln (B) logB (C) = ln (C)
• log2 (20,234,456) = ln (20,234,567)/ln(2) = 16.823/0.693 = round
up the integer 25
– Using: logA (B) logB (C) = logA (C)
• log2 (20,234,456) = log10 (20,234,567)/log10 (2) = 7.306/0.30 =
integer 25
– Need 25 bits minimum: 225 = 33,554,432 >
20,234,567 elements; n = 25
• 20,234,567 symbols with meaning or CODE are used
• 13,319,865 symbols are extra; not used
5
8/27/15
Function
Minimization,
K-Maps
Karnaugh Maps
Switching/Boolean functions can generally be
simplified by using the algebraic techniques.
However, two problems arise when algebraic
procedures are used:
6
8/27/15
7
8/27/15
Karnaugh Maps
1-variable map: minterm and maxterm coding
X minterm maxterm symbols
0 X’ X m0/M0
1 X X’ m1/M1
X 01 01
m0 m1 X’ X minterm
X 01 01
M0 M1 X X’ maxterm
m1 m3
8
8/27/15
(a)
Karnaugh Maps
2-variable map: minterm and maxterm coding
X Y minterm maxterm symbols
0 0 X’Y’ X+Y m0/M0
0 1 X’Y X+Y’ m1/M1
1 0 XY’ X’+Y m2/M2
1 1 XY X’+Y’ m3/M3
X Y 01 X Y 01
m0 m1
minterm M0 M1
maxterm
10
10
m2 m3 M2 M3
9
8/27/15
Karnaugh Maps
2-variable map: observe, minterms
Karnaugh Maps
2-variable map: observe, maxterms
10
8/27/15
3 Variables K-Maps
11
8/27/15
12
8/27/15
Location of Minterms on a
Three-Variable Karnaugh Map
13
8/27/15
14
8/27/15
Simplification of a
Three-Variable Function
15
8/27/15
Complement of Map
The map for the complement
of F is formed by replacing
0’s with 1’s and 1’s with 0’s
on the map of F.
F′ = c′ + ab
16
8/27/15
4 Variable K-Map
17
8/27/15
Location of Minterms on
Four-Variable Karnaugh Map
Each minterm is located Most significant variable = A
adjacent to the four
terms with which it can
combine. For example,
m5 (0101) could
combine with m1
(0001), m4 (0100),
m7 (0111), or m13
(1101).
18
8/27/15
Simplification of
Four-Variable Functions
19
8/27/15
Simplification of an Incompletely
Specified Function
Example
Use a four variable Karnaugh map to find the minimum
product of sums for f:
f = x′z′ + wyz + w′y′z′ + x′y
20
8/27/15
Example
Implicants, Prime
Implicants,
Essential Prime
Implicants
21
8/27/15
Implicants
Prime
Implicant
Implicant
Implicant
Implicant
Prime
Implicant
Prime
Implicant
22
8/27/15
Examples
23
8/27/15
Essential
Prime
Implicants
Prime
Implicants
Implicants
Example
24
8/27/15
no
All uncovered 1’s checked?
yes
Find a minimum set of prime implicants
which cover the remaining 1’s on the map.
Example
25
8/27/15
5 Variable K-Maps
26
8/27/15
Example
27
8/27/15
Example
Example
F(A, B, C, D, E) = Ʃ m(0, 1, 3, 8, 9, 14, 15, 16, 17, 19, 25, 27, 31)
28
8/27/15
Example
29
8/27/15
Veitch Diagrams
30
8/27/15
00 m0 m1 m3 m2 m6 m7 m5 m4
Most significant variables drive rows and least significant variables drive columns.
31
8/27/15
32
8/27/15
33
8/27/15
Binary Number
Conversions
34
8/27/15
35
8/27/15
• Consists of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
• Coefficients are multiplied by powers of 10
• Said to be of base 10 or radix 10
MSB LSB
36
8/27/15
(724.06)8
MSD LSD
(6AC.9E)16
MSD LSD
37
8/27/15
Octal and Hex are easier to read and more compact to display
than Binary
Number Base
Conversions
38
8/27/15
39
8/27/15
Integer part:
Fraction part:
40
8/27/15
Conversion (a)
ECE 238L – ECE Dept, Fall 2015
81
Conversion (b)
ECE 238L – ECE Dept, Fall 2015
82
41
8/27/15
Conversion (c)
ECE 238L – ECE Dept, Fall 2015
83
Integer part:
42
8/27/15
Fraction part:
Conversion (d)
ECE 238L – ECE Dept, Fall 2015
86
43
8/27/15
44
8/27/15
45
8/27/15
Binary ó Hexadecimal
Conversion
How about conversion between Octal and Hexadecimal and vice versa?
Octal to Hexadecimal
– (31.7)8
– 31. 7
– 011 001. 111 (binary equivalent)
– 0001 1001. 1110 (group digits by four)
– (19.E)16
46
8/27/15
Hexadecimal to Octal
– (AB.6)16
– A B. 6
– 1010 1011. 0110 (binary equivalent)
– 010 101 011. 011 (group digits by three)
– (253.3)8
Arithmetic
Operations
47
8/27/15
Arithmetic Operations
Addition
The addition table for binary numbers is
0+0=0
0+1=1
1+0=1
1 + 1 = 0 and carry 1 to next column
Carrying 1 to a column
is equivalent to adding 1 to that column.
48
8/27/15
Binary Addition:
1) can only use a 0 or a 1
2) Carry, use with the next significant position higher
Subtraction (a)
The subtraction table for binary numbers is
0–0=0
0–1=1 and borrow 1 from the next column
1–0=1
1–1=0
49
8/27/15
Subtraction (b)
EXAMPLES OF BINARY SUBTRACTION:
Subtraction (c)
A detailed analysis of the borrowing process for this example, indicating first
a borrow of 1 from column 1 and then a borrow of 1 from column 2, is as
follows:
50
8/27/15
Multiplication (a)
The multiplication table for binary numbers is
0x0=0
0x1=0
1x0=0
1x1=1
Multiplication (b)
The following example illustrates
multiplication of 1310 by 1110 in binary:
51
8/27/15
Multiplication (c)
When doing binary multiplication, a common way to avoid carries greater than 1
is to add in the partial products one at a time as illustrated by the following
example:
1111 multiplicand
1101 multiplier
1111 1st partial product
0000 2nd partial product
(01111) sum of first two partial products
1111 3rd partial product
(1001011) sum after adding 3rd partial product
1111 4th partial product
11000011 final product (sum after adding 4th
partial product)
Binary Division
Binary division is similar to decimal division, except it is much easier
because the only two possible quotient digits are 0 and 1.
We start division by comparing the divisor with the upper bits of the
dividend.
If we cannot subtract without getting a negative result, we move one
place to the right and try again.
If we can subtract, we place a 1 for the quotient above the number we
subtracted from and append the next dividend bit to the end of the
difference and repeat this process with this modified difference until we
run out of bits in the dividend.
52
8/27/15
Binary Division
The following example illustrates
division of 14510 by 1110 in binary:
Complements
53
8/27/15
Complements
Allows us to represent negative numbers and
we can do subtraction using addition.
Complements
The r’s complement is defined as N*
N=dn-1dn-2 ….d2d1d0.d-1d-2 …d-m
*
N = 0 if N = 0
*
N = r n − N if N > 0
54
8/27/15
Complements
The (r-1)’s complement is defined as N-
N=dn-1dn-2 ….d2d1d0.d-1d-2 …d-m
−
N = (r n − r − m ) − N
* −
NOTE: N = N + r−m
€
−
NOTE: if m=0 then N = (r n −1) − N
€ * −
N = N +1
Complements
55
8/27/15
Complements
Example: base 2 (r = 2)
• N = 101011.011; n = 6; m = 3
• 2’s complement
– N* = 26 – N = 1000000 – 101011.011 = 10100.101
• 1’s complement
– N- = (26 – 2-3) – N = 10100.1
• Note: N* = N- + r -3 = 10100.1 + 0.001 = 10100.101
Complements
Most of the time we work with integer numbers; i.e. no
fractional part
• 2’s complement
* *
N = 0 if N = 0; N = r n − N if N > 0
*
or N = rn − N
• Note: given a negative integer represented by its 2’s
complement, N*, we can obtain the magnitude of the
integer by taking the 2’s complement of N*
€
56
8/27/15
Complements
Most of the time we work with integer numbers; i.e. no
fractional part
• 1’s complement
−
N = (r n −1) − N
−
or N = (r n −1) − N
• Note: given a negative integer represented by its 1’s
complement, N-, we can obtain the magnitude of the
integer by taking the 1’s complement of N-
€
* −
• NOTE: N = N +1
Complements: Algorithms
2’s complement
– Leave all least significant zeros unchanged as well as the
least significant one
– Replace 1’s by 0’s and 0’s by 1’s in all higher significant
digits
1’s complement
– Flip every bit, replace 0’s by 1’s and 1’s by 0’s
57
8/27/15
• 0110 M = 610
• -0011 N = -310
• Result is 310
• 0110 M
• + 1101 N*
• --------------
• 10011 carry not used, 0011 is correct answer
58
8/27/15
• 0011 M = 310
• -0111 N = -710
• Result is -410
• 0011 M
• + 1001 N*
• --------------
• 1100 no carry; take complement and add
negative sign -0100
59
8/27/15
• 1001 M = 910
• -0100 N = -410
• Result is 510
• 1001 M
• + 1011 N-
• --------------
• 10100 add 1 to 0100, result is 0101
• 0100 M = 410
• -1001 N = -910
• Result is -510
• 0100 M
• + 0110 N-
• --------------
• 1010, no carry, take 1’s complement 0101 and
add negative sign in front, result is -0101
60
8/27/15
OVERFLOW
61
8/27/15
Range of numbers: -8 to +7
62
8/27/15
63
8/27/15
64
8/27/15
Signed Binary
Numbers
65
8/27/15
66
8/27/15
67
8/27/15
More on Binary
Codes
68
8/27/15
Binary Codes
• Digital systems represent and manipulate many
other discrete elements of information (not only
binary numbers)
• If information is continuous (analog signal) we must
discretize it by sampling it at specified intervals
(Nyquist Sampling Theorem) - ADC
• If information is discrete (digital signal) we must
convert it to an analog signal if peripheral device
requires it (DAC)
• Bit = binary digit
Binary Codes
• How many distinct elements can we represent with n
bits?
– N = 2n
– n-bit code found by counting in binary from 0 to (2n – 1)
• We can let a set of bits represent distinct elements
by a CODE
• EX: wish to find a binary code to represent the
colors RED, BLUE, and WHITE
– Have 3 distinct elements
– Need log2 N = n (number of binary digits) Ceiling Function
– Need two bits minimum: 22 = 4 > 3 elements; n = 2
• Symbols with meaning or CODE for colors: 00 – RED; 01 – BLUE; 10 –
WHITE; 11 Not Used
69
8/27/15
Binary Codes
Although most large computers work internally with binary numbers, the
input-output equipment generally uses decimal numbers. Because most
logic circuits only accept two-valued signals, the decimal numbers must
be coded in terms of binary signals. In the simplest form of binary code,
each decimal digit is replaced by its binary equivalent. For example,
937.25 is represented by:
Decimal Codes
• Binary codes for decimal digits require a minimum of
4 binary digits or bits
– Have 10 distinct elements ( 0 – 9)
– Need log2 N = n (number of binary digits) Ceiling Function
– Need four bits minimum: 24 = 16 > 10 elements; n = 4
• 0000 0
• 0001 1
BCD Code: Binary Coded
• 0010 2
Decimal
• 0011 3
• 0100 4
• 0101 5
• NOTE: 10 of 16 possible
• 0110 6
distinct elements are used; 6
• 0111 7
are not used.
• 1000 8 • One-to-one mapping to avoid
• 1001 9 ambiguity.
• This is not a conversion it is a
CODE.
ECE 238L – ECE Dept, Fall 2015
140
70
8/27/15
71
8/27/15
72
8/27/15
73
8/27/15
Alphanumeric Codes
• Permit representation of information other than just
numbers
– We can represent
• Alphabetic characters
• Punctuation marks
• Special symbols #, $, *, @, …
• Numbers
– Most common codes
ASCII: American Standard for Information Interchange
• 7 bits + parity bit = 8 bit code
• 27 = 128 different symbols (elements)
EBCDIC: Extended BCD Interchange Code
• 8 bits + parity bit = 9 bit code
• 28 = 256 different symbols (elements)
UNICODE: Universal Code
• 16 bits
• 216 = 65,536 different symbols (elements)
• Universal characters; encode all world languages
74
8/27/15
Table 1-3
ASCII code
(incomplete)
75
8/27/15
7-segment Code
76
8/27/15
77
8/27/15
TABLE 2.5
78
8/27/15
Q&A
79