2

I am confused on how to do conversion from one's complement to two's complement. Suppose we have 10101101 in one's complement. How to convert it to two's complement?

Thanks

UserMoon
  • 75
  • 1
  • 1
  • 4

1 Answers1

7

Just look at the definitions:

One's complement means that the bits in the negation of the value are complement (inversion) of all the bits in the original.

Two's complement of an N-bit number is defined as the result of subtracting the original N-bit number from 2^N. The effect of this operation has the same result on the original number as taking the one's complement and adding 1.

In this case then, if 10101101 is the one's complement, just add one to get the two's complement, which would be 10101110. Or, doing it the long way:

  1. One's complement = 10101101
  2. Original number = 01010010 (invert the bits per definition of one's complement)
  3. Two's complement = 2^8 - 01010010 = 100000000 - 01010010 = 10101110
lurker
  • 56,987
  • 9
  • 69
  • 103
  • Okay, thanks... Then, if we want to get from two's complement negative number to binary representation. How would we do that? Would we substract one? – UserMoon Oct 30 '14 at 16:41
  • @FemX get to binary representation of what? The original, unnegated number? If you have a 2's complement and want to negate it back to he original, you would reverse the operation: subtract 1, then take the complement (NOTE: "complement" is its own identity inverse, so complement of the complement of X is the original X). – lurker Oct 30 '14 at 16:42
  • @FemX, if you have a 2's complement and you want the 1's complement, yes, you would just subtract 1. – lurker Oct 30 '14 at 16:49