You are on page 1of 79

8/27/15

ECE 238L – 2
Computer Logic Design

Dr. Ramiro Jordan


rjordan@ece.unm.edu

ECE 238L – ECE Dept, Fall 2015


1

Textbook and Website


Fundamentals of Digital and
Computer Design with VHDL

Authors:
Richard S. Sandige
Michael L. Sandige

Website:
http://www.mhhe.com/sandige

ECE 238L – ECE Dept, Fall 2015


2

1
8/27/15

Codes, Function Minimization,


Kaurnaugh-Maps, Implicants,
Number Base Conversions,
Arithmetic Operations,
Complements
Dr. Ramiro Jordan
rjordan@ece.unm.edu

ECE 238L – ECE Dept, Fall 2015


3

Binary Codes

ECE 238L – ECE Dept, Fall 2015


4

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

ECE 238L – ECE Dept, Fall 2015


5

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

ECE 238L – ECE Dept, Fall 2015


6

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  
               

ECE 238L – ECE Dept, Fall 2015


7

Binary Codes for Decimal Digits


8-4-2-1
Decimal Code 6-3-1-1 Excess-3 2-out-of-5 Gray
Digit Code Code Code Code
(BCD)
0 0000 0000 0011 00011 0000
1 0001 0001 0100 00101 0001
2 0010 0011 0101 00110 0011
3 0011 0100 0110 01001 0010
4 0100 0101 0111 01010 0110
5 0101 0111 1000 01100 1110
6 0110 1000 1001 10001 1010
7 0111 1001 1010 10010 1011
8 1000 1011 1011 10100 1001
9 1001 1100 1100 11000 1000

ECE 238L – ECE Dept, Fall 2015


8

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

ECE 238L – ECE Dept, Fall 2015


9

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

ECE 238L – ECE Dept, Fall 2015


10

5
8/27/15

Function
Minimization,
K-Maps

ECE 238L – ECE Dept, Fall 2015


11

Karnaugh Maps
Switching/Boolean functions can generally be
simplified by using the algebraic techniques.
However, two problems arise when algebraic
procedures are used:

1. The procedures are difficult to apply in a systematic


way.
2. It is difficult to tell when you have arrived at a
minimum solution.

The Karnaugh map method is generally faster and


easier to apply than other simplification methods.

ECE 238L – ECE Dept, Fall 2015


12

6
8/27/15

Rules for Combining Squares


(Simplification, Elimination)
1.  Can combine 2k adjacent cells; where 0≤k≤n and n is
the number of variables; implies that
•  Can combine 1, 2, 4, 8, 16, etc, cells; a power of 2
•  Cannot combine 3, 5, 6, 7, 9, etc cells

2.  Want to combine the largest number of cells possible to


eliminate as many variables as possible, implies that:
•  Combine 2 cells, eliminate 1 variable
•  Combine 4 cells, eliminate 2 variables
•  Combine 8 cells, eliminate 3 variables
•  Combine 2n, eliminate n variables

ECE 238L – ECE Dept, Fall 2015


13

Rules for Combining Squares


(Simplification, Elimination)

3.  Once a minterm (maxterm) is used we can use it again


4.  Avoid redundancy!!!

ECE 238L – ECE Dept, Fall 2015


14

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

ECE 238L – ECE Dept, Fall 2015


15

Two- Variable Karnaugh Maps

Just like a truth table, the Karnaugh map of a function


specifies the value of the function for every combination of
values of the independent variables.
Most significant variable = A

Least significant variable = B


m0 m2

m1 m3

ECE 238L – ECE Dept, Fall 2015


16

8
8/27/15

Example: two – variable K-map

(a)

ECE 238L – ECE Dept, Fall 2015


17

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

Most significant variable = X Least significant variable = Y

X Y 01 X Y 01
m0 m1
minterm M0 M1
maxterm
10

10

m2 m3 M2 M3

ECE 238L – ECE Dept, Fall 2015


18

9
8/27/15

Karnaugh Maps
2-variable map: observe, minterms

m0 + m1 = X’Y’ + X’Y = X’(Y’+Y) = X’(1) = X’ row 1


m0 + m2 = X’Y’ + XY’ = (X’+X)Y’ = (1)Y’ = Y’ col 1
m2 + m3 = XY’ + XY = X(Y’+Y) = X(1) = X row 2
m1 + m3 = X’Y + XY = (X’+X)Y = (1)Y = Y col 2

Any 2 minterms in adjacent squares that are ORed will


cause removal of the different variable

ECE 238L – ECE Dept, Fall 2015


19

Karnaugh Maps
2-variable map: observe, maxterms

M0M1 = (X+Y)(X+Y’) = X row 1


M0M2 = (X+Y)(X’+Y) = Y col 1
M2M3 = (X’+Y)(X’+Y’) = X’ row 2
M1M3 = (X+Y’)(X’+Y’) = Y’ col 2

Any 2 maxterms in adjacent squares that are ANDed


will cause removal of the different variable

ECE 238L – ECE Dept, Fall 2015


20

10
8/27/15

Examples: two – variable K-Maps


EX: simplify the function F = XY’ + X’Y

EX: simplify the function F = X’Y’ + XY’ + X’Y

ECE 238L – ECE Dept, Fall 2015


21

3 Variables K-Maps

ECE 238L – ECE Dept, Fall 2015


22

11
8/27/15

Three- Variable Karnaugh Maps

Most significant variable = X

Least significant variable = Z

ECE 238L – ECE Dept, Fall 2015


23

Three- Variable Karnaugh Maps


EX: mo + m1 + m2 + m3 =

NOTE: sequence 00 – 01 – 11 – 10; only one bit


changes (Gray Code)

ECE 238L – ECE Dept, Fall 2015


24

12
8/27/15

Karnaugh Map for


Three-Variable Function
Most significant variable = A

Least significant variable = C

ECE 238L – ECE Dept, Fall 2015


25

Location of Minterms on a
Three-Variable Karnaugh Map

ECE 238L – ECE Dept, Fall 2015


26

13
8/27/15

Karnaugh Map of F(a, b, c) =


Σm(1, 3, 5) = ∏ M(0, 2, 4, 6, 7)

ECE 238L – ECE Dept, Fall 2015


27

Karnaugh Maps for Product


Terms

ECE 238L – ECE Dept, Fall 2015


28

14
8/27/15

f(a,b,c) = abc' + b'c + a'

ECE 238L – ECE Dept, Fall 2015


29

Simplification of a
Three-Variable Function

ECE 238L – ECE Dept, Fall 2015


30

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

ECE 238L – ECE Dept, Fall 2015


31

Karnaugh Maps Which Illustrate


the Consensus Theorem

ECE 238L – ECE Dept, Fall 2015


32

16
8/27/15

Function with Two Minimal Forms

ECE 238L – ECE Dept, Fall 2015


33

4 Variable K-Map

ECE 238L – ECE Dept, Fall 2015


34

17
8/27/15

Four- Variable Karnaugh Maps

Most significant variable = X

Least significant variable = W

ECE 238L – ECE Dept, Fall 2015


35

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).

Least significant variable = D

ECE 238L – ECE Dept, Fall 2015


36

18
8/27/15

Plot of acd + a’b + d’

ECE 238L – ECE Dept, Fall 2015


37

Simplification of
Four-Variable Functions

ECE 238L – ECE Dept, Fall 2015


38

19
8/27/15

Simplification of an Incompletely
Specified Function

ECE 238L – ECE Dept, Fall 2015


39

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

First, we will plot the 1’s on a Karnaugh map.

ECE 238L – ECE Dept, Fall 2015


40

20
8/27/15

Example

Then, from the 0’s we get:


f ' = y'z + wxz' + w'xy

Finally, we can complement f ' to get a


minimum product of sums of f :

f = (y + z′)(w′ + x′ + z)(w + x′ + y′)

ECE 238L – ECE Dept, Fall 2015


41

Implicants, Prime
Implicants,
Essential Prime
Implicants

ECE 238L – ECE Dept, Fall 2015


42

21
8/27/15

Implicants and Prime Implicants

Any single 1 or any group of 1’s which can be combined


together on a map of the function F represents a product
term which is called an implicant of F.

A product term implicant is called a prime implicant if it


cannot be combined with another term to eliminate a
variable.

ECE 238L – ECE Dept, Fall 2015


43

Implicants

Prime
Implicant
Implicant

Implicant

Implicant
Prime
Implicant

Prime
Implicant

ECE 238L – ECE Dept, Fall 2015


44

22
8/27/15

Determination of All Prime


Implicants

ECE 238L – ECE Dept, Fall 2015


45

Examples

ECE 238L – ECE Dept, Fall 2015


46

23
8/27/15

Essential Prime Implicants


If a minterm is covered by only one prime implicant, that
prime implicant is said to be essential, and it must be
included in the minimum sum of products.

Essential
Prime
Implicants

Prime
Implicants

Implicants

ECE 238L – ECE Dept, Fall 2015


47

Example

Note: 1’s shaded in


blue are covered by
only one prime
implicant. All other
1’s are covered by
at least two prime
implicants.

ECE 238L – ECE Dept, Fall 2015


48

24
8/27/15

Choose a 1 which has not been covered.

Find all adjacent 1’s and X’s.

Are the chosen 1 and its adjacent 1’s


and X’s covered by a single term?
no
yes
That term is an essential prime implicant. Loop it.

no
All uncovered 1’s checked?
yes
Find a minimum set of prime implicants
which cover the remaining 1’s on the map.

Flowchart for Determining a Minimum Sum of Products Using a


Karnaugh Map

ECE 238L – ECE Dept, Fall 2015


49

Example

Shaded 1’s are covered by


only one prime implicant.
Essential prime implicants:
A′B, AB′D′

Then AC′D covers the


remaining 1’s.

ECE 238L – ECE Dept, Fall 2015


50

25
8/27/15

5 Variable K-Maps

ECE 238L – ECE Dept, Fall 2015


51

Five-Variable Karnaugh Maps


A five-variable map can be constructed in three dimensions
by placing one four-variable map on top of a second one.
Terms in the bottom layer are numbered 0 through 15 and
corresponding terms in the top layer are numbered 16
through 31, so that the terms in the bottom layer contain A'
and those in the top layer contain A.
To represent the map in two dimensions, we will divide each
square in a four-variable map by a diagonal line and place
terms in the bottom layer below the line and terms in the top
layer above the line.

ECE 238L – ECE Dept, Fall 2015


52

26
8/27/15

A Five-Variable Karnaugh Map

Note that terms m0


and m20 do not
combine because
they are in different
layers and different
columns (they
differ in two
variables).

Most significant variable = A

Least significant variable = E

ECE 238L – ECE Dept, Fall 2015


53

Example

Each term can be


adjacent to exactly five
other terms: four in the
same layer and one in
the other layer.

ECE 238L – ECE Dept, Fall 2015


54

27
8/27/15

Example

When checking for


adjacencies, each term
should be checked
against the five possible
adjacent squares.
P1 and P2 are essential
prime implicants.

ECE 238L – ECE Dept, Fall 2015


55

Example

P1, P2, P3, and P4 are


essential prime
implicants.

F(A, B, C, D, E) = Ʃ m(0, 1, 3, 8, 9, 14, 15, 16, 17, 19, 25, 27, 31)

ECE 238L – ECE Dept, Fall 2015


56

28
8/27/15

Example

ECE 238L – ECE Dept, Fall 2015


57

Other Forms of Karnaugh Maps

Instead of labeling the sides of a Karnaugh map


with 0’s and 1’s, some people prefer to use Veitch
diagrams. In Veitch diagrams, A = 1 for the half of
the map labeled A, and A = 0 for the other half. The
other variables have a similar interpretation.

ECE 238L – ECE Dept, Fall 2015


58

29
8/27/15

Veitch Diagrams

ECE 238L – ECE Dept, Fall 2015


59

Two alternative forms of five-variable maps are also used.


One form simply consists of two four-variable maps side-by-
side.
A modification of this uses a mirror image map. In this map,
first and eighth columns are “adjacent” as are second and
seventh columns, third and sixth columns, and fourth and
fifth columns.

ECE 238L – ECE Dept, Fall 2015


60

30
8/27/15

Five- Variable Karnaugh Maps

Most significant variable = A

Least significant variable = E

ECE 238L – ECE Dept, Fall 2015


61

Five- Variable Karnaugh Maps


000 001 011 010 110 111 101 100

00 m0 m1 m3 m2 m6 m7 m5 m4

01 m8 m9 m11 m10 m14 m15 m13 m12

11 m24 m25 m27 m26 m30 m31 m29 m28

10 m16 m17 m19 m18 m22 m23 m21 m20

Most significant variables drive rows and least significant variables drive columns.

ECE 238L – ECE Dept, Fall 2015


62

31
8/27/15

Side-by-side Form of Five-


Variable Karnaugh Maps

ECE 238L – ECE Dept, Fall 2015


63

Mirror Image Form of Five-


Variable Karnaugh Maps

ECE 238L – ECE Dept, Fall 2015


64

32
8/27/15

Rules for Combining Squares


(Simplification, Elimination)
1.  Can combine 2k adjacent cells; where 0≤k≤n and n is
the number of variables; implies that
•  Can combine 1, 2, 4, 8, 16, etc, cells; a power of 2
•  Cannot combine 3, 5, 6, 7, 9, etc cells

2.  Want to combine the largest number of cells possible to


eliminate as many variables as possible, implies that:
•  Combine 2 cells, eliminate 1 variable
•  Combine 4 cells, eliminate 2 variables
•  Combine 8 cells, eliminate 3 variables
•  Combine 2n, eliminate n variables

ECE 238L – ECE Dept, Fall 2015


65

Rules for Combining Squares


(Simplification, Elimination)

3.  Once a minterm (maxterm) is used we can use it again


4.  Avoid redundancy!!!

ECE 238L – ECE Dept, Fall 2015


66

33
8/27/15

Binary Number
Conversions

ECE 238L – ECE Dept, Fall 2015


67

Binary Number Conversions


•  The primary number
systems used in digital
systems are decimal
(base-10), binary
(base-2), octal (base-8)
and hexadecimal
(base-16)
•  Octal and Hexadecimal
number systems are
used to represent
binary numbers in a
more compact form

ECE 238L – ECE Dept, Fall 2015


68

34
8/27/15

Binary Codes for Decimal Digits


8-4-2-1
Decimal Code 6-3-1-1 Excess-3 2-out-of-5 Gray
Digit Code Code Code Code
(BCD)
0 0000 0000 0011 00011 0000
1 0001 0001 0100 00101 0001
2 0010 0011 0101 00110 0011
3 0011 0100 0110 01001 0010
4 0100 0101 0111 01010 0110
5 0101 0111 1000 01100 1110
6 0110 1000 1001 10001 1010
7 0111 1001 1010 10010 1011
8 1000 1011 1011 10100 1001
9 1001 1100 1100 11000 1000

ECE 238L – ECE Dept, Fall 2015


69

Review of Decimal Number System


•  Consider the symbol 9,437.25
1.  9 – 1000s 9000 most significant digit (MSD)
2.  4 – 100s 400
3.  3 – 10s 30 Weighted-Positional Number System
4.  7 – 1s 7
5.  2 – 1/10s .2
6.  5 – 1/100s .05 least significant digit (LSD)
•  Add them up and you get 9,437.25
•  To be more exact 9,437.25 should be written as: 9x103 + 4x102 +
3x101 + 7x100 + 2x10-1 + 5x10-2
•  By convention we write only the coefficients (9,437.25)10
–  10 indicates the base, in this case is base 10 or decimal
–  Position of coefficient is a power (weight) of the base and
specifies the information to be conveyed

ECE 238L – ECE Dept, Fall 2015


70

35
8/27/15

Review of Decimal Number System

•  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

We can generalize to any base or radix “r”.


•  “r” is any integer greater than 1 (r > 1)
•  Why r > 1?
•  Consists of “r” possible values: 0, 1 , ….. r-1
•  Coefficients are multiplied by powers of “r”

ECE 238L – ECE Dept, Fall 2015


71

Binary Number System

•  Consists of two possible values (coefficients): 0 and 1


•  Binary digits are called bits (short for binary digits)
•  Byte = 8-bit binary number
•  Nibble = 4-bit binary number
•  Coefficients are multiplied by powers of 2
•  Binary system is of base 2 or radix 2
•  EX: (101.01)2 = 1x22 + 0x21 + 1x20 + 0x2-1 + 1x2-2
= (5.25)10

MSB LSB

ECE 238L – ECE Dept, Fall 2015


72

36
8/27/15

Octal Number System

•  Consists of eight possible values (coefficients): 0, 1,


2, 3, 4, 5, 6, and 7
•  Coefficients are multiplied by powers of 8
•  Octal system is of base 8 or radix 8
•  EX: (724.06)8 = 7x82 + 2x81 + 4x80 + 0x8-1 + 6x8-2 = 448
+ 16 + 4 + 0.015625 = (468.015625)10

(724.06)8

MSD LSD

ECE 238L – ECE Dept, Fall 2015


73

Hexadecimal Number System

•  Consists of sixteen possible values (coefficients): 0,


1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
•  Coefficients are multiplied by powers of 16
•  Hexadecimal system is of base 16 or radix 16
•  EX: (6AC.9E)16 = 6x162 + Ax161 + Cx160 + 9x16-1 +
Ex16-2 = 1536 + 160 + 12 + 0.5 + 0.05468=
(1708.55468)10

(6AC.9E)16

MSD LSD

ECE 238L – ECE Dept, Fall 2015


74

37
8/27/15

Binary, Octal and Hexadecimal


NOTE: binary, octal and hex numbers are all powers of 2
•  23 = 8: each octal digit corresponds to 3 binary digits; with 3
binary digits we can represent 8 combinations; 000 to 111, 0 to
7 decimal
•  24 = 16: each hexadecimal digit corresponds to 4 binary digits;
with 4 binary digits we can represent 16 combinations; 0000 to
1111, 0 to F (15) decimal

Octal and Hex are easier to read and more compact to display
than Binary

ECE 238L – ECE Dept, Fall 2015


75

Number Base
Conversions

ECE 238L – ECE Dept, Fall 2015


76

38
8/27/15

Number of Base “r” to Decimal


Number
(number)r (number)10

Any base to decimal: form products by multiplying the


coefficients times appropriate powers of the base, and then
sum the products

EX: (101.01)2 = 1x22 + 0x21 + 1x20 + 0x2-1 + 1x2-2 =(5.25)10

EX: (724.06)8 = 7x82 + 2x81 + 4x80 + 0x8-1 + 6x8-2 = 448 + 16 + 4 +


0.015625 = (468.015625)10

EX: (6AC.9E)16 = 6x162 + Ax161 + Cx160 + 9x16-1 + Ex16-2 = 1536 +


160 + 12 + 0.5 + 0.05468= (1708.55468)10

ECE 238L – ECE Dept, Fall 2015


77

Decimal Number to Number of


Base “r”
(number)10 (number)r

We will use an Algorithm: efficient procedure (sequence of steps),


recipe

Decimal to any base:


1.  Separate number into an integer part and a fraction part
2.  Integer portion is repeatedly divided by the base to which we
are converting. NOTE: remainders are the appropriate
coefficients
3.  Fractional part is repeatedly multiplied by the base to which we
are converting. NOTE: integer portions of resulting numbers
are the appropriate coefficients
4.  Combine the resulting answers from 2 and 3

ECE 238L – ECE Dept, Fall 2015


78

39
8/27/15

EXAMPLE: Convert (25.375)10 to base 2 (binary)


Integer = 25 Fraction = 0.375

Integer part:

25/2 = 12 + 1 (least significant bit - lsb)


12/2 = 6 + 0
6/2 = 3 + 0
3/2 = 1 + 1
1/2 = 0 + 1 (most significant bit - msb)
Read back in this
(25)10 = (11001)2 direction

ECE 238L – ECE Dept, Fall 2015


79

EXAMPLE: Convert (25.375)10 to base 2 (binary)


Integer = 25 Fraction = 0.375

Fraction part:

.375 * 2 = .75 + 0 (most significant bit - msb)


.75 * 2 = .5 + 1
.5 * 2 = 0 + 1 (least significant bit - lsb)
Read back in this
(0.375)10 = (011)2 direction

Result: (25.375)10 = (11001.011)2

ECE 238L – ECE Dept, Fall 2015


80

40
8/27/15

EXAMPLE: Convert 5310 to binary.

Conversion (a)
ECE 238L – ECE Dept, Fall 2015
81

EXAMPLE: Convert .62510 to binary.

Conversion (b)
ECE 238L – ECE Dept, Fall 2015
82

41
8/27/15

EXAMPLE: Convert 0.710 to binary.

Conversion (c)
ECE 238L – ECE Dept, Fall 2015
83

EXAMPLE: Convert (720.75)10 to base 8 (octal)


Integer = 720 Fraction = 0.75

Integer part:

720/8 = 90 + 0 (least significant bit - lsd)


90/8 = 11 + 2
11/8 = 1 + 3
1/8 = 0 + 1 (most significant bit - msd)

(720)10 = (1320)8 Read back in this


direction

ECE 238L – ECE Dept, Fall 2015


84

42
8/27/15

EXAMPLE: Convert (720.75)10 to base 8 (octal)


Integer = 720 Fraction = 0.75

Fraction part:

.75 * 8 = .0 + 6 (most significant bit - msd)


and (least significant bit - lsd)

(0.75)10 = (0.6)8 Read back in this


direction
Result: (720.75)10 = (1320.6)8

ECE 238L – ECE Dept, Fall 2015


85

EXAMPLE: Convert 231.34 to base 7.

Conversion (d)
ECE 238L – ECE Dept, Fall 2015
86

43
8/27/15

Binary, Octal and


Hexadecimal
Conversions

ECE 238L – ECE Dept, Fall 2015


87

How to Convert Between Binary,


Octal and Hexadecimal
Conversion of base is done by partitioning
•  If needed add zeros to extreme left when converting the integer
portion
•  Add zeros to extreme right when converting fractional part
•  Binary to Octal
–  Partition binary number into groups of three digits starting
from binary point
•  Octal to Binary
–  Each octal digit is converted to its 3-digit binary equivalent
•  Binary to Hexadecimal
–  Partition binary number into groups of four digits starting
from binary point
•  Hexadecimal to Binary
–  Each hex digit is converted to its 4-digit binary equivalent

ECE 238L – ECE Dept, Fall 2015


88

44
8/27/15

How to Convert Between Binary,


Octal and Hexadecimal
Binary to Octal
–  Partition binary number into groups of three digits starting
from binary point
–  (101100.01101)2
–  101 100. 011 010
–  5 4. 3 2
–  (54.32)8
Octal to Binary
–  Each octal digit is converted to its 3-digit binary equivalent
–  (3.1)8
–  3. 1
–  011. 001
–  (011.001)2

ECE 238L – ECE Dept, Fall 2015


89

How to Convert Between Binary,


Octal and Hexadecimal
Binary to Hexadecimal
–  Partition binary number into groups of four digits starting
from binary point
–  (111010.011)2
–  0011 1010. 0110
–  3 A. 6
–  (3A.6)16
Hexadecimal to Binary
–  Each hex digit is converted to its 4-digit binary equivalent
–  (6.D)16
–  6. D
–  0110. 1101
–  (0110.1101)2

ECE 238L – ECE Dept, Fall 2015


90

45
8/27/15

Binary ó Hexadecimal
Conversion

Conversion from binary to hexadecimal (and conversely) can be done by


inspection because each hexadecimal digit corresponds to exactly four
binary digits (bits).

How about conversion between Octal and Hexadecimal and vice versa?

ECE 238L – ECE Dept, Fall 2015


91

EXAMPLE: Convert (31.7)8 to Hex.

Octal to Hexadecimal
–  (31.7)8
–  31. 7
–  011 001. 111 (binary equivalent)
–  0001 1001. 1110 (group digits by four)
–  (19.E)16

ECE 238L – ECE Dept, Fall 2015


92

46
8/27/15

EXAMPLE: Convert (AB.6)16 to octal.

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

ECE 238L – ECE Dept, Fall 2015


93

Arithmetic
Operations

ECE 238L – ECE Dept, Fall 2015


94

47
8/27/15

Arithmetic Operations

•  Numbers in base “r” follow the same rules as


for decimal numbers; (r > 1)
•  When using another base be sure to use only
the “r” allowable digits; (r > 1: 0, 1, …, r-1)

ECE 238L – ECE Dept, Fall 2015


95

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.

ECE 238L – ECE Dept, Fall 2015


96

48
8/27/15

Add 1310 and 1110 in binary.

Binary Addition:
1) can only use a 0 or a 1
2) Carry, use with the next significant position higher

ECE 238L – ECE Dept, Fall 2015


97

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

Borrowing 1 from a column


is equivalent to subtracting 1 from that column.

ECE 238L – ECE Dept, Fall 2015


98

49
8/27/15

Subtraction (b)
EXAMPLES OF BINARY SUBTRACTION:

ECE 238L – ECE Dept, Fall 2015


99

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:

ECE 238L – ECE Dept, Fall 2015


100

50
8/27/15

Multiplication (a)
The multiplication table for binary numbers is

0x0=0
0x1=0
1x0=0
1x1=1

ECE 238L – ECE Dept, Fall 2015


101

Multiplication (b)
The following example illustrates
multiplication of 1310 by 1110 in binary:

ECE 238L – ECE Dept, Fall 2015


102

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)

ECE 238L – ECE Dept, Fall 2015


103

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.

ECE 238L – ECE Dept, Fall 2015


104

52
8/27/15

Binary Division
The following example illustrates
division of 14510 by 1110 in binary:

ECE 238L – ECE Dept, Fall 2015


105

Complements

ECE 238L – ECE Dept, Fall 2015


106

53
8/27/15

Complements
Allows us to represent negative numbers and
we can do subtraction using addition.

Two types for each base “r” number system (r>1)


–  The r’s complement; “radix complement”
–  The (r-1)’s complement; “diminished radix
complement”
–  Given a positive number N in base r, with integer
part of n digits, and a fractional part of m digits

N=dn-1dn-2 ….d2d1d0.d-1d-2 …d-m

ECE 238L – ECE Dept, Fall 2015


107

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

ECE 238L – ECE Dept, Fall 2015


108

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

ECE 238L – ECE Dept, Fall 2015


109

Complements

Example: base 10 (r = 10)


•  N = 43.375; n = 2; m = 3
•  10’s complement
–  N* = 102 – 43.375 = 100 – 43.375 = 56.625
•  9’s complement
–  N- = (102 – 10-3) – 43.375 = 99.999 – 43.375 = 56.624
•  Note: N* = N- + r -3 = 56.624 + 0.001 = 56.625

ECE 238L – ECE Dept, Fall 2015


110

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

ECE 238L – ECE Dept, Fall 2015


111

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*

ECE 238L – ECE Dept, Fall 2015


112

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

ECE 238L – ECE Dept, Fall 2015


113

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

NOTE: 2’s complement = 1’s complement + 1

ECE 238L – ECE Dept, Fall 2015


114

57
8/27/15

Subtraction using r’s complement


•  Assume M and N are two positive numbers
•  Want to perform the following operation M - N
•  Algorithm
–  Add M to the r’s complement of N
•  M – N = M + N*
–  Inspect result for end carry
•  If end carry occurs, discard it
•  If no end carry occurs, then take the r’s complement of result
and place a negative sign in front

ECE 238L – ECE Dept, Fall 2015


115

EXAMPLE: binary subtraction, 2’s


complement; 4-bit arithmetic

•  0110 M = 610
•  -0011 N = -310
•  Result is 310
•  0110 M
•  + 1101 N*
•  --------------
•  10011 carry not used, 0011 is correct answer

ECE 238L – ECE Dept, Fall 2015


116

58
8/27/15

EXAMPLE: binary subtraction, 2’s


complement; 4-bit arithmetic

•  0011 M = 310
•  -0111 N = -710
•  Result is -410
•  0011 M
•  + 1001 N*
•  --------------
•  1100 no carry; take complement and add
negative sign -0100

ECE 238L – ECE Dept, Fall 2015


117

Subtraction using (r-1)’s


complement
•  Assume M and N are two positive numbers
•  Want to perform the following operation M - N
•  Algorithm
–  Add M to the (r-1)’s complement of N
•  M – N = M + N-
–  Inspect result for end carry
•  If end carry occurs, add 1 to LSB (end-around carry)
•  If no end carry occurs, then take the (r-1)’s complement of
result and place a negative sign in front

ECE 238L – ECE Dept, Fall 2015


118

59
8/27/15

EXAMPLE: binary subtraction, 1’s


complement; 4-bit arithmetic

•  1001 M = 910
•  -0100 N = -410
•  Result is 510
•  1001 M
•  + 1011 N-
•  --------------
•  10100 add 1 to 0100, result is 0101

ECE 238L – ECE Dept, Fall 2015


119

EXAMPLE: binary subtraction, 1’s


complement; 4-bit arithmetic

•  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

ECE 238L – ECE Dept, Fall 2015


120

60
8/27/15

EXAMPLE: binary subtraction, 1’s


and 2’s complement

Perform 1100 - 1100


•  1’s complement
•  1100 + 0011 = (carry = 0) 1111 (positive zero)
•  Result = -0000 (negative zero)
•  2’s complement
•  1100 + 0100 = (carry = 1) 0000
•  Result = 0000

ECE 238L – ECE Dept, Fall 2015


121

OVERFLOW

When the word length is n bits, we say that an


overflow has occurred if the correct
representation of the sum (including sign)
requires more than n bits (n+1 bits).

An overflow occurs if adding two positive numbers


gives a negative answer or if adding two negative
numbers gives a positive answer.

ECE 238L – ECE Dept, Fall 2015


122

61
8/27/15

2’s Complement Addition (a)


4-bit arithmetic

Range of numbers: -8 to +7

ECE 238L – ECE Dept, Fall 2015


123

2’s Complement Addition (b)


4-bit arithmetic

ECE 238L – ECE Dept, Fall 2015


124

62
8/27/15

2’s Complement Addition (c)


4-bit arithmetic

ECE 238L – ECE Dept, Fall 2015


125

1’s Complement Addition (b)


4-bit arithmetic

ECE 238L – ECE Dept, Fall 2015


126

63
8/27/15

1’s Complement Addition (c)


4-bit arithmetic

ECE 238L – ECE Dept, Fall 2015


127

1’s Complement Addition (d)


8-bit arithmetic

ECE 238L – ECE Dept, Fall 2015


128

64
8/27/15

2’s Complement Addition (d)


8-bit arithmetic

ECE 238L – ECE Dept, Fall 2015


129

Signed Binary
Numbers

ECE 238L – ECE Dept, Fall 2015


130

65
8/27/15

Signed Binary Numbers


•  Sign of a number must be represented with a 0 or a 1
in the leftmost position (by convention)
–  0 = positive and 1 = negative
•  Digital system (Computer) does not care whether
number is + or -, user is responsible for keeping
track
•  Not convenient for computers
•  Number = (sign) (magnitude)
–  n-bits = (1-bit) (n-1 bits)
•  Correction must be made when subtraction is
performed

ECE 238L – ECE Dept, Fall 2015


131

EXAMPLE: Signed-Magnitude System (127)10


Use 8-bit arithmetic, limited by hardware (register)
Integer part:
127/2 = 63 + 1 (least significant bit - lsb)
63/2 = 31 + 1
31/2 = 15 + 1
15/2 = 7 + 1
7/2 = 3 + 1
3/2 = 1 + 1
1/2 = 0 + 1 (most significant bit - msb)
Read back in this
direction
(127)10 is then: sign = 0 magnitude = 1111111
(-127)10 is then: sign = 1 magnitude = 1111111

ECE 238L – ECE Dept, Fall 2015


132

66
8/27/15

EXAMPLE: Signed 1’s complement (127)10


Use 8-bit arithmetic, limited by hardware (register)
•  Positive numbers start with a 0, msb
•  Negative numbers start with a 1, msb
•  Convenient for digital systems

(127)10 is then: 01111111


(-127)10 is then: 10000000
(1)10 is then: 00000001
(-1)10 is then: 11111110

(11111111)2 is then (-0)10 NOTE: 1’s complement has


(0000000)2 is then (+0)10 two representations of zero

ECE 238L – ECE Dept, Fall 2015


133

EXAMPLE: Signed 2’s complement (127)10


Use 8-bit arithmetic, limited by hardware (register)
•  Positive numbers start with a 0, msb
•  Negative numbers start with a 1, msb
•  Convenient for digital systems

(127)10 is then: 01111111


(-127)10 is then: 10000001
(1)10 is then: 00000001
(-1)10 is then: 11111111

(11111111)2 is then (-1)10 NOTE: 2’s complement has


(0000000)2 is then (0)10 one representation of zero

ECE 238L – ECE Dept, Fall 2015


134

67
8/27/15

Signed Binary Integers (word length n = 4)

NOTE: for a word length N


•  the range of 2’s complement numbers that can be represented is
•  -2N-1 to (2N-1 – 1)
•  The range of 1’s complement numbers that can be represented is
•  –(2N-1 -1) to (2N-1 – 1)

ECE 238L – ECE Dept, Fall 2015


135

More on Binary
Codes

ECE 238L – ECE Dept, Fall 2015


136

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

ECE 238L – ECE Dept, Fall 2015


137

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

ECE 238L – ECE Dept, Fall 2015


138

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:

ECE 238L – ECE Dept, Fall 2015


139

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

Binary Codes for Decimal Digits


8-4-2-1
Decimal Code 6-3-1-1 Excess-3 2-out-of-5 Gray
Digit Code Code Code Code
(BCD)
0 0000 0000 0011 00011 0000
1 0001 0001 0100 00101 0001
2 0010 0011 0101 00110 0011
3 0011 0100 0110 01001 0010
4 0100 0101 0111 01010 0110
5 0101 0111 1000 01100 1110
6 0110 1000 1001 10001 1010
7 0111 1001 1010 10010 1011
8 1000 1011 1011 10100 1001
9 1001 1100 1100 11000 1000

ECE 238L – ECE Dept, Fall 2015


141

Decimal numbers represented


in various binary codes

ECE 238L – ECE Dept, Fall 2015


142

71
8/27/15

Decimal to Reflective Gray Code conversion


using the mirror method

ECE 238L – ECE Dept, Fall 2015


143

Binary to RGC conversion method

ECE 238L – ECE Dept, Fall 2015


144

72
8/27/15

Modulo-2 addition table

ECE 238L – ECE Dept, Fall 2015


145

RGC to binary conversion method

ECE 238L – ECE Dept, Fall 2015


146

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

ECE 238L – ECE Dept, Fall 2015


147

7-bit ASCII character et code (nonextended form)

ECE 238L – ECE Dept, Fall 2015


148

74
8/27/15

Table 1-3
ASCII code
(incomplete)

ECE 238L – ECE Dept, Fall 2015


149

Error Detection Codes


•  Most computers manipulate an 8-bit quantity as a
single unit: 8-bits = byte
–  Or multiple bytes, examples
•  16-bits = 2 bytes = 1 word
•  32-bits = 4 bytes = 1 longword

•  Some codes make use of a parity bit


Parity bit = extra bit included with a message to make total
number of 1’s ODD or EVEN
–  EX: ASCII letter A is 1000001 (7-bit code)
–  With ODD parity = 1 1000001 odd number of 1’s in message
“A”
–  With EVEN parity = 0 1000001 even number of 1’s in
message “A”
–  An error is detected if check parity (receiving end) is not
equal to parity adopted. Detects only an ODD combination
of errors. EVEN combination of errors is undetectable.

ECE 238L – ECE Dept, Fall 2015


150

75
8/27/15

ECE 238L – ECE Dept, Fall 2015


151

7-segment Code

ECE 238L – ECE Dept, Fall 2015


152

76
8/27/15

7-segment code for a 7-segment display

ECE 238L – ECE Dept, Fall 2015


153

Letter Display System

ECE 238L – ECE Dept, Fall 2015


154

77
8/27/15

TABLE 2.5

ECE 238L – ECE Dept, Fall 2015


155

VHDL code for letter display system

ECE 238L – ECE Dept, Fall 2015


156

78
8/27/15

ECE 238L – ECE Dept, Fall 2015


157

Q&A

ECE 238L – ECE Dept, Fall 2015


158

79

You might also like