Presentation is loading. Please wait.

Presentation is loading. Please wait.

Two’s Complement Shortcut

Similar presentations


Presentation on theme: "Two’s Complement Shortcut"— Presentation transcript:

1 Two’s Complement Shortcut
To take the two’s complement of a number: copy bits from right to left up to, and including, the first “1” flip remaining bits to the left (1’s comp) + 1 (flip) (copy)

2 Why does it work? Adding 1 to any binary number will invert digits until the first zero is encountered When the bit is zero, adding 1 yields 1, with no carry remaining bits are unaffected If the bit is 1, adding 1 yields 0, with a 1 carry Process will then repeat at the next bit Since 1 is being added to the already inverted bits of the one’s complement, inverted 1 bits get converted back to their original zero state Until the first 0 is encountered, then the inversion stops “original” 1 is preserved Remaining bits stay “flipped” relative to original number

3 2’s Complement “Sign” bit
Restrict positive numbers to have a leading “0” Restricted to the N-1 lower bits of an N-bit 2’s complement number When, the one’s complement is taken… Highest order bit becomes a one Adding 1 to make it 2’s complement cannot change that bit (based on previous discussion) So… Positive 2’s complement numbers have a leading zero Negative 2’s complement numbers have a leading one Highest order bit acts as a sign bit!

4 Two’s Complement Signed Integers
MS bit is sign bit – it has weight –2n-1. Range of an n-bit number: -2n-1 through 2n-1 – 1. The most negative number (-2n-1) has no positive counterpart. -23 22 21 20 1 2 3 4 5 6 7 -23 22 21 20 1 -8 -7 -6 -5 -4 -3 -2 -1


Download ppt "Two’s Complement Shortcut"

Similar presentations


Ads by Google