Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1...

24
Lecture 4

Transcript of Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1...

Page 1: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Lecture 4

Page 2: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Basic Binary Arithmetic

2

Single-bit Addition Single-bit Subtraction

s

0

1

1

0

c

0

0

0

1

x y

0

0

1

1

0

1

0

1

Carry Sum

d

0

1

1

0

x y

0

0

1

1

0

1

0

1

Difference

What logic function is this?

What logic function is this?

Page 3: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

3

Binary Multiplication

Page 4: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Binary Multiplication

4

0 0 1 1x 0 x 1 x 0 x 1 0 0 0 1

Product

Page 5: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Binary Multiplication

5

Examples:

00111100x 10101100

10110001x 01101101

Page 6: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

6

Unsigned and Signed Binary Numbers

Page 7: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Unsigned and Signed Numbers

8-bit Binary number.

What is the decimal equivalent of this binary number?

7

10011010

Page 8: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Unsigned and Signed Numbers

8

bn 1– b1 b0

Magnitude

MSB

(a) Unsigned number

bn 1– b1 b0

MagnitudeSign

(b) Signed number

bn 2–

0 denotes1 denotes

+– MSB

Page 9: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

ECE 301 - Digital Electronics 9

Unsigned Binary Numbers

Page 10: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Unsigned Binary Numbers

For an n-bit unsigned binary number, all n bits are used to represent the

magnitude of the number.

** Cannot represent negative numbers.

ECE 301 - Digital Electronics10

Page 11: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Unsigned Binary Numbers For an n-bit binary number

0 <= D <= 2n – 1 where D = decimal equivalent value

For an 8-bit binary number: 0 <= D <= 28 – 1 28 = 256

For a 16-bit binary number: 0 <= D <= 216 – 1 216 = 65536

11

Page 12: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

ECE 301 - Digital Electronics 12

Signed Binary Numbers

Page 13: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Signed Binary NumbersFor an n-bit signed binary number, n-1 bits are used to represent the

magnitude of the number;

the leftmost bit (MSB) is, generally, used to indicate the sign of the

number.

0 = positive number1 = negative number

13

Page 14: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Signed Binary Numbers

Three representations for signed binary numbers:

1. Sign-and-Magnitude2. One's Complement3. Two's Complement

ECE 301 - Digital Electronics14

Page 15: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Signed Binary Numbers

Sign-and-Magnitude Representation

ECE 301 - Digital Electronics15

Page 16: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Sign-and-Magnitude For an n-bit signed binary number,

The MSB (leftmost bit) is the sign bit. The remaining n-1 bits represent the magnitude.

- (2n-1 - 1) <= D <= + (2n-1 – 1) Includes a representation for -0 and +0.

The design of arithmetic circuits for sign-and-magnitude binary numbers is difficult.

16

Page 17: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Sign-and-Magnitude

Example:

What is the Sign-and-Magnitude binary number representation for the following

decimal values, using 8 bits:

+ 97- 68

ECE 301 - Digital Electronics17

Page 18: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Sign-and-MagnitudeExample:

Can the following decimal numbers be represented using Sign-and-Magnitude representation and 8

bits?

- 127+ 128- 212+ 255 ECE 301 - Digital Electronics18

Page 19: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

Signed Binary Numbers

• One's Complement Representation

ECE 301 - Digital Electronics19

Page 20: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

One's Complement

An n-bit positive number (P) is represented in the same way as in the Sign-and-Magnitude representation.

The sign bit (MSB) = 0. The remaining n-1 bits represent the magnitude.

ECE 301 - Digital Electronics 20

Page 21: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

One's Complement An n-bit negative number (N) is represented

using the “One's Complement” of the equivalent positive number (P).

N' = One's Complement representation for the negative number N.

N' = (2n – 1) – P where P = |N|

The sign bit (MSB) = 1 for all negative numbers using the One's Complement representation.

21

Page 22: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

One's ComplementExample:

Determine the One's Complement representation for the following negative numbers, using 8 bits:

- 11- 107- 74

ECE 301 - Digital Electronics22

Page 23: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

One's Complement The One's Complement representation of N

can also be determined using the bit-wise complement of P.

N = n-bit negative number P = |N| N' = One's Complement representation of N. N' = bit-wise complement of P

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

ECE 301 - Digital Electronics 23

Page 24: Lecture 4. Basic Binary Arithmetic 2 Single-bit AdditionSingle-bit Subtraction s 0 1 1 0 c 0 0 0 1 xy 0 0 1 1 0 1 0 1 Carry Sum d 0 1 1 0 xy 0 0 1 1 0.

One's ComplementExample:

Determine the One's Complement representation (using the bit-wise

complement) for the following negative numbers, using 8 bits:

- 11- 107- 74

ECE 301 - Digital Electronics24