binarycomplement

Binary into 2's compliment


if I convert the binary number 000000 into 2's compliment I will get 1's compliment (invert) = 111111 2's compliment (add +1) = here I run into a problem, does this return 000000 and the 1 gets discarded or does this return 1000000?

Thanks in advance!


Solution

  • It discards the 1. The condition is similar to the Arithmetic Overflow.

    Strength of two's complement is that it helps us retain a binary representation when signed numbers are to be considered, because in mathematics, the value of 0 is same as that of -0. If we have to give up one entire bit just for sign, then, in a 4-bit word, 0000 would denote 0 and 1000 would denote -0, wasting one representation. The two's complement helps get rid of this. If we assume 4-bit words: val -val bits of val two's complement bits of -val (1's complement + 1) 0 0 0000 0000 (1111+0001) 1 -1 0001 1111 (1110+0001) 2 -2 0010 1110 (1101+0001) 3 -3 0011 1101 (1100+0001) ... 7 -7 0111 1001 (1000+0001) 8 -8 (no rep) 1000 (0111+0001) (note that for -8 you have one's complement of 8 in an unsigned manner, i.e.8 = 1000 and hence its one's complement is 0111).

    Thus you gain a representation for -8 by making 0 and -0 have the same bit pattern, i.e. 0000. Using this, for n bits, we can represent all integer values between -2^(n-1) to 2^(n-1)-1.