Top Banner
1 Digital Design: Number Systems Credits: Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic Design, 5/e, Thomson, 2004
36

1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

Dec 31, 2015

Download

Documents

Neal Wood
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

1

Digital Design: Number Systems

Credits:Slides adapted from:J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006C.H. Roth, Fundamentals of Logic Design, 5/e, Thomson, 2004

Page 2: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

2

Positional Number Systems

A number is represented by a string of digits, where each digit position has an associated weight and it has the following form:

dp1dp2 d1d0 . d1d2 dn

The value of the number is given by:

ip

nii rdD

1

Page 3: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

3

Binary Numbers

The general form of a binary number of p+n binary digits (bits) is:

bp1bp2 b1b0 . b1b2 bn

and its value is:

ip

niibB 2

1

Page 4: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

4

Octal and Hexadecimal Numbers

The octal number system uses radix 8, while the hexadecimal number system uses radix 16

The octal and hex number systems are useful for representing multibit numbers

Page 5: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

5

Conversion from Binary to Decimal

ip

niibB 2

1

Method: summation

Example:

101110110012 = 1 210 + 0 29 + 1 28 + 1 27 + 1 26 + 0 25 +

1 24 + 1 23 + 0 22 + 0 21 + 1 20 = 149710

Page 6: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

6

Conversion from Decimal to Binary

Method: successive divisions

Example:

Page 7: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

7

EXAMPLE: convert 5310 to binary

Page 8: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

8

EXAMPLE: convert .625ten to binary

Page 9: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

9

EXAMPLE: convert 0.710 to binary.

Page 10: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

10

EXAMPLE: convert 231.34 to base 7.

Page 11: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

11

Addition of Binary Numbers

EXAMPLE: Add 1310 and 1110 in binary.

Page 12: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

12

Subtraction of Binary Numbers

EXAMPLES:

Page 13: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

13

Representation of Negative Numbers

Signed-Magnitude Representation 10ten 10ten

001010two 101010two

The number zero has two representations (+0 and 0) An n-bit signed-magnitude number lies within the range

(2n1 1) through (2n1 1) To add signed-magnitude numbers we must examine the signs of

the addends to determine what to do …

Radix Complement Representation Diminished Radix Complement Representation

Page 14: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

14

Representing Numbers ????

Key observation: Numbers are just strings of symbols. The meaning (value) we assign to each string instance (pattern) is up to us. If the string is n symbols (digits) long and each symbol can take up to different r instances (radix) then we can form rn different patterns.

“Common sense” characteristics of a system number: Assign a different value to each different patternSplit the patterns equally between positive numbers and

negative numbersThe mechanic of doing arithmetic operations should be as

“simple’ as possible

Page 15: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

15

Complement Number Systems While the signed-magnitude system negate a number by

changing its sign, a complement number system negates a number by taking its complement.

Radix-complement RepresentationThe complement of an n-digit number D is obtained by subtracting it from rn

rn – D = ((rn1)D) 1

Diminished Radix-complement RepresentationIn a diminished radix-complement system the complement of an n-digit number D is obtained by subtracting it from rn1

Page 16: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

16

Complement Number Systems

Page 17: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

17

Complement Number Systems

Page 18: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

18

Complement Number Systems

Once we know how to compute the diminished-radix complement of a number, computing the radix-complement is very simple:

radix complement = diminished-radix complement + 1

0

5

1

2

3

6 4

7

8

9

Page 19: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

19

C2 Number System

For binary numbers, the radix complement is called two’s complement (C2).

The MSB of a number in this system serves as the sign bit. Negative numbers have MSB equal to 1 Positive numbers have MSB equal to 0

The range of representable numbers is: –(2n1) through +(2n11)

Zero has only one representation

Page 20: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

20

Two’s Complement Number System

00000001

0010

0011

0100

0101

0110

011110001001

1010

1011

1100

1101

1110

1111

01

2

3

4

5

6

7-8-7

-6

-5

-4

-3

-2

-1

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

Page 21: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

21

C1 Number System

For binary numbers, the diminished-radix complement is called one’s complement (C1).

The MSB of a number in this system serves as the sign bit. Negative numbers have MSB equal to 1 Positive numbers have MSB equal to 0

The range of representable numbers is: –(2n11) through +(2n11)

Zero has two representations: positive zero (00 00) and negative zero (11 11)

Page 22: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

22

Summary of Signed Number Systems

Page 23: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

23

C1 Number System

In the C1 number system to negate an n-bit number all we have do is to flip (invert) all the bits

Page 24: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

24

C2 Number System

In the C2 number system to negate an n-bit number requires two steps:

invert all bits of the number (i.e. take the C1 of the number) and then add 1

Page 25: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

25

“Playing” with the C2 notation

The sum of a number and its inverted representation must be 111….111two, which in C2 represent –1

01XX X1X 1XX

Page 26: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

26

C2 EXAMPLES

Page 27: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

27

C2 sign extension

As far as m > n, it is possible to convert n-bit numbers into m-

bit numbers, but some care is needed :

copy the most significant bit (the sign bit) into the other bits

0010 0000 0010

1010 1111 1010

This procedure is referred as "sign extension"

Page 28: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

28

C2 Addition and Subtraction

1. Addition of 2 positive numbers, sum < 2n –1.

2. Addition of 2 positive numbers, sum ≥ 2n –1

Page 29: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

29

C2 Addition and Subtraction

3. Addition of positive and negative numbers (negative number has greater magnitude).

4. Addition of positive and negative numbers (positive number has greater magnitude).

Page 30: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

30

C2 Addition and Subtraction

5. Addition of two negative numbers, |sum| ≤ 2n –1.

6. Addition of two negative numbers, | sum | > 2n –1.

Page 31: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

31

Detecting overflow Overflow occurs when the value affects the sign bit:

adding two positives yields a negative adding two negatives gives a positive subtract a negative from a positive and get a negative subtract a positive from a negative and get a positive

No overflow when adding a positive and a negative number No overflow when subtracting two numbers of same sign

Consider the operations A + B, and A – B Can overflow occur if B is 0 ? Can overflow occur if A is 0 ?

cannot occur !

can occur ! (for AB if B=2n1)

Page 32: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

32

Binary Codes for Decimal Numbers

Page 33: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

33

Gray Code

Page 34: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

34

Character Codes

Page 35: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

35

N-cubes and Hamming distance

Page 36: 1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.

36

Traversing a 3-cube in Gray code order