'What is the 2's complement of -17?

What will be the binary value of -17 and how to find the 2's complement of -17?



Solution 1:[1]

Assuming an 8-bit word, start with the binary form of 17. = 00010001

Then invert the bits: = 11101110

Then just add 1: = 11101111.

If you've got a 16-, 32- or 64-bit word then you'll have a load more leading 1s.

Solution 2:[2]

Even if you do not assume anything, you have to just keep the leftmost bit significant. Start with the word itself, 10001. Then invert gives the one's, 01110 Now add 1 to this number. 01111. But to keep the left most bit significant, append a one there eg,101111 in terms of the minimum number of bits required (6 here).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Trevor Tippins
Solution 2 MItrajyoti Kusari