Presentation is loading. Please wait.

Presentation is loading. Please wait.

2’s Complement Another system that lets us represent negative numbers

Similar presentations


Presentation on theme: "2’s Complement Another system that lets us represent negative numbers"— Presentation transcript:

1 2’s Complement Another system that lets us represent negative numbers
MSB is STILL the sign bit, but there is no negative zero Negative numbers count backwards and wrap around Calculating 2’s complement (Pos  Neg) Flip the bits ( 01 and 10 ) Add 1

2 Example ( Pos  Neg ) 110  -110 00012  11112 Flip bits: 1110
110  00012  Flip bits: 1110 Add 1: +0001 1111

3 Another Example ( Pos  Neg )
2510  Flip bits: Add 1:

4 Your Turn Assuming an 8-bit restriction, what is in 2’s complement? Flip bits Add 1 Answer:

5 Your Turn Assuming an 8-bit restriction, what is in 2’s complement? Flip bits Add 1 Answer:

6 Example ( Neg Pos ) -410  410 11002  01002 Flip bits: 0011
-410  11002  Flip bits: 0011 Add 1: +0001 0100

7 Another Example ( Neg  Pos )
Flip bits: Add 1:

8 Your Turn Assuming 2’s complement, what is the decimal value of ? Flip bits Add 1 Answer: -710

9 Your Turn Assuming 2’s complement, what is the decimal value of ? Flip bits Add 1 Answer: 22

10 2’s Complement Chart Binary Decimal 0111 7 0110 6 0101 5 0100 4 0011 3
0010 2 0001 1 0000 1111 -1 1110 -2 1101 -3 1100 -4 1011 -5 1010 -6 1001 -7 1000 -8 Binary Decimal 7 6 5 4 3 2 1 -1 -2 -3 -4 -5 -6 -7 -8

11 SHORTCUT! Find the 1 on the farthest right
Flip all the bits to the left of the 1 (DO NOT FLIP THE 1) Example: 4210 

12 Awesomeness of 2’s Complement
No more negative zero Lower minimum value: -(2N-1) So what’s the big deal? Everything is addition No need for special hardware to do subtraction

13 2’s Complement Addition
Just like normal positive binary addition You MUST restrict the number of bits IGNORE any overflow bits maintain bit-size restriction

14 Positive Addition Example
= 1610 Assuming 2’s complement

15 Negative Addition Example
= -1610 NOTE: We ignored the last overflow bit on the left!

16 Your Turn Show the binary addition of = -17

17 Subtraction Example 1610 – 410 = 1610 + -410 = 1210 000100002
NOTE: We ignored the last overflow bit on the left!

18 Your Turn Show the binary subtraction of 23 – 10 = 13

19 Overflow / Underflow Problem
Addition and bit-size restriction allow for possible overflow / underflow Overflow – when the addition of two binary numbers yields a result that is greater than the maximum possible value Underflow – when the addition/subtraction of two binary numbers yields a result that is less than the minimum possible value

20 Overflow Example Assume 4-bit restriction and 2’s complement
Maximum possible value: 24-1 – 1 = 7 = 910  not good!

21 Underflow Example Assume 4-bit restriction and 2’s complement
Minimum possible value: -(24-1) = -8 = -1010  not good!


Download ppt "2’s Complement Another system that lets us represent negative numbers"

Similar presentations


Ads by Google