Transcript
Page 1: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

ECE 301 – Digital Electronics

Representation of Negative Numbers,Binary Arithmetic of Negative Numbers,

andBinary Codes

(Lecture #11)

The slides included herein were taken from the materials accompanying Fundamentals of Logic Design, 6th Edition, by Roth and Kinney,

and were used with permission from Cengage Learning.

Page 2: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 2

Representation of Negative Numbers

(continued)

Page 3: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 3

Signed Binary Numbers

Representations for signed binary numbers:

1. Sign and Magnitude2. 1's Complement3. 2's Complement

Page 4: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 4

Signed Binary Numbers

Arithmetic circuits are difficult to design for Sign and Magnitude binary numbers.

Consequently, this number system is not typically used in digital (computer) systems.

Instead other number systems, namely the 1's and 2's Complements, are more commonly used.

As we will see, it is rather easy to design arithmetic circuits for binary numbers represented in these number systems.

Page 5: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 5

1's Complement

A positive number, N, is represented in the same way as in the Sign and Magnitude representation.

For an n-bit number, The leftmost bit (sign bit) = 0.

Indicating a positive number. The remaining n-1 bits represent the

magnitude.

Page 6: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 6

1's Complement

A negative number, -N, is represented by the “1's complement” of the positive number, N.

N' = 1's complement representation for -N. For an n-bit signed binary number,

The leftmost bit (sign bit) = 1 for all negative numbers in the 1's Complement system.

N' = (2n – 1) – N

Page 7: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 7

1's Complement: Examples

Using 8 bits, determine the 1's Complement representation for the following negative

numbers:

-15-102

Page 8: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 8

1's Complement

The 1's Complement representation for -N can also be determined by taking the bit-wise complement of N.

N' = 1's Complement representation for -N. For an n-bit signed binary number,

i.e. complement N, bit-by-bit

N' = bit-wise complement of N

Page 9: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 9

1's Complement: Examples

Using 8 bits, determine the 1's Complement representation for the following negative

numbers:

-15-102

(Use the bit-wise complement)

Page 10: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 10

1's Complement

For an n-bit 1's Complement binary number,

Includes a representation for +0 and -0. Represents an equal number of positive and

negative values.

- (2n-1 – 1) <= N <= + (2n-1 – 1)

Page 11: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 11

1's Complement

To determine the magnitude of a negative number, -N, that is represented by its 1's Complement, N', simply take the “1's complement” of the 1's Complement.

N = (2n – 1) – N'

N = bit-wise complement of N'orpositive #

1's complement rep.for negative #

Page 12: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 12

2's Complement

A positive number, N, is represented in the same way as in the Sign and Magnitude representation.

For an n-bit number, The leftmost bit (sign bit) = 0.

Indicating a positive number. The remaining n-1 bits represent the

magnitude.

Page 13: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 13

2's Complement

A negative number, -N, is represented by the “2's complement” of the positive number, N.

N* = 2's complement representation for -N. For an n-bit signed binary number,

The leftmost bit (sign bit) = 1 for all negative numbers in the 2's Complement system.

N* = (2n) – N

Page 14: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 14

2's Complement: Examples

Using 8 bits, determine the 2's Complement representation for the following negative

numbers:

-12-95

Page 15: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 15

2's Complement

The 1's and 2's Complement representations for a negative number, -N, are related as follows:

N* = (2n) – N

N' = (2n - 1) – N

N* = N' +1

Page 16: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 16

2's Complement

Thus, the 2's Complement representation for -N can also be determined by adding 1 to the 1's Complement representation for -N.

N' = 1's Complement representation for -N. N* = 2's Complement representation for -N.

For an n-bit signed binary number,

N* = N' + 1

Page 17: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 17

2's Complement: Examples

Using 8 bits, determine the 2's Complement representation for the following negative

numbers:

-12-95

(Use the 1's complement)

Page 18: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 18

2's Complement

For an n-bit 2's Complement binary number,

Includes only one representation for 0. Represents an additional negative value.

- (2n-1) <= N <= + (2n-1 – 1)

Page 19: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 19

2's Complement

To determine the magnitude of a negative number, -N, that is represented by its 2's Complement, N*, simply take the “2's complement” of the 2's Complement.

N = (2n) – N*

N = (N*)' + 1orpositive #

2's complement rep. for negative #

bit-wise complement of 2's complement

Page 20: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 20

Signed Binary Numbers

Page 21: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 21

Binary Arithmeticof

Signed Binary Numbers

Page 22: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 22

2's Complement Addition

Addition of n-bit signed binary numbers is straightforward using the 2's Complement number system.

Addition is carried out in the same way as for n-bit positive numbers.

Carry from the sign bit (leftmost bit) is ignored. Overflow occurs if the correct result (including

the sign bit) cannot be represented in n bits.

Page 23: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 23

2's Complement Addition: Example

Using 2's Complement addition and 8-bit representation, add the following numbers:

-47 + 83

Did overflow occur?

Page 24: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 24

2's Complement Addition: Example

Using 2's Complement addition and 8-bit representation, add the following numbers:

-32 + -105

Did overflow occur?

Page 25: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 25

2's Complement Addition: Example

Using 2's Complement addition and 8-bit representation, add the following numbers:

19 + 52

Did overflow occur?

Page 26: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 26

2's Complement Addition: Example

Using 2's Complement addition and 8-bit representation, add the following numbers:

64 + 78

Did overflow occur?

Page 27: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 27

2's Complement Subtraction

Subtraction can be implemented using addition.

Determine the 2's Complement representation for the negative number -B.

Use 2's Complement addition to add A and -B.

A – B = A + (-B)

Page 28: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 28

2's Complement Subtraction: Example

Subtract the following numbers, using 2's Complement addition and 8-bit representation:

64 – 78

Did overflow occur?

Page 29: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 29

2's Complement Subtraction: Example

Subtract the following numbers, using 2's Complement addition and 8-bit representation:

-35 – 62

Did overflow occur?

Page 30: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 30

2's Complement Subtraction: Example

Subtract the following numbers, using 2's Complement addition and 8-bit representation:

14 – (-59)

Did overflow occur?

Page 31: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 31

2's Complement Subtraction: Example

Subtract the following numbers, using binary subtraction and 8-bit representation:

27 – 45

Can this subtraction be carried out?

Page 32: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 32

1's Complement Addition

Similar to 2's Complement Addition of n-bit signed binary numbers.

However, rather than ignore the carry-out from the sign (leftmost) bit, add it to the least significant bit (LSB) of the n-bit sum.

Known as the end-around carry.

Page 33: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 33

1's Complement Addition: Example

Using 1's Complement addition and 8-bit representation, add the following numbers:

-31 + -84

Did overflow occur?

Page 34: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 34

1's Complement Addition: Example

Using 1's Complement addition and 8-bit representation, add the following numbers:

52 + 73

Did overflow occur?

Page 35: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 35

Overflow

The general rule for detecting overflow when performing 2's Complement or 1's Complement Addition:

An overflow occurs when the addition of two positive numbers results in a negative number.

An overflow occurs when the addition of two negative numbers results in a positive number.

Overflow cannot occur when adding a positive number to a negative number.

Page 36: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 36

Binary Codes

Page 37: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 37

Binary Codes

Weighted Codes Each position in the code has a specific weight Decimal value of code can be determined

Unweighted Codes Positions of code do not have a specific weight Decimal value assigned to each code

Page 38: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 38

Binary Codes

n-bit Weighted Codes Code: an-1an-2an-3...a1a0 Weights: wn-1, wn-2, wn-3, ..., w1, w0 Decimal Value: an-1 x wn-1 + an-2 x wn-2 + …

+ a1 x w1 + a0 x w0 4-bit Weighted Code

Code: a3a2a1a0

Page 39: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 39

Binary Codes

Examples of 4-bit weighted codes 8-4-2-1

4 bits → 16 code words Only 10 code words required to represent

decimal digits 6-3-1-1

4 bits → 16 code words Excess-3 (obtained from 8-4-2-1)

4 bits → 16 code words

Page 40: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 40

Binary Codes

Examples of unweighted codes 2-out-of-5 Code

Exactly 2 of the 5 bits are “1” for a valid code word. 10 valid code words.

Gray Code Code values for successive decimal digits differ in

exactly one bit. 4 bits → 16 code words.

Page 41: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 41

Binary Codes

Decimal Digit

8-4-2-1 Code (BCD)

6-3-1-1 Code

Excess-3 Code

2-out-of-5 Code

Gray Code

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

Page 42: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 42

Binary Coded Decimal (BCD)

4-bit binary number used to represent each decimal digit.

Weighted code: 8-4-2-1 Binary values 0000 … 1001 used to represent

decimal values 0 … 9. Binary values 1010 … 1111 not used. Very different from binary representation.

Page 43: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 43

Binary Coded Decimal

In BCD, each decimal digit is replaced by its binary equivalent value.

Example:

Binary: 937.2510 = 1110101001.012

Page 44: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 44

ASCII

American Standard Code for Information Interchange Common code for the storage and transfer of

alphanumeric characters. 7-bit Weighted Code

Can represent 128 characters

Used to represent letters, numbers, and other characters

Any word or number can be represented using its ASCII code.

Page 45: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 45

ASCII Code (incomplete)

Page 46: ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included

Spring 2011 ECE 301 - Digital Electronics 46

Questions?


Top Related