Doubt in two compiment

MrChips

Joined Oct 2, 2009
30,708
To form 1's complement, invert every bit.

To form 2's complement, take the 1's complement and add 1.

Hence the 2's complement of 000 is 000 with a carry. Hence 1000 is also correct if the register is only three bits.

You have to define the size of the register.
 

MrAl

Joined Jun 17, 2014
11,389
It does not works.Then why the statement raised and widely being used in many books

Hi,

I think it does work, but the question comes up about why you would want to use it. To do it the other way, we would have to complement all the bits and then add 1, but adding 1 means we might generate a ripple carry that involves all the bits which means we might have to work on the bits twice and also the second time in sequence. Using the more abstract way, we would only have to look at the bits once and make a decision for each bit only once, so there may be an advantage with some types of processors. With modern processors however i dont think there is an advantage because they probably have a built in function already (which may actually already do it that shorter way) or even just one complement and one addition means just two quick integer instructions and it's done. This can be done on at least 64 bits at a time, possibly more.
 
Top