Not sure if I am in the correct place on this forum but this is the nearest area I could find.

Basically I have one question regarding converting binary numbers to two's complement negative binary numbers.

From what I have read you add a 1 if it's negative after inverting all the numbers. What if there is already a 1 at the beginning. Do you move to the next 0 and change it to a 1 to negate it?


9 Years
Discussion Span
Last Post by mvmalderen

Let me explain this using an example:
If we want to store number -6 as a binary value we use the two complement:
-> Assume we're working with a byte ...
-> If we set all bits of a byte to '1' we get 11111111 which corresponds with the decimal number 255 -> Now we increase the corresponding decimal value (if all bits of the binary number are set to '1') by '1' so we get 256 (255+1) -> Now we subtract 6 from 256: 256-6 = 250 (this is the two complement of '-6') ...

=> Now if we want to subtract 6 from 17 what do we do ?
-> Well, first we rewrite '-6' as it's two complement as described above ...
-> Since 17-6 is actually the same as 17+ -6 , we can rewrite this expression using the two-complement: 17+250
-> If we make the addition of 17 and 250 the result is equal to 267 (17+250) which corresponds with 100001011 in binary ...
-> Now we just throw away the first bit and what we keep is the following: (1)00001011 which corresponds with the decimal number 11 and that's the exact result of 17-6 :) ...
The (1) in (1)00001011 is the indication of the bit we threw away ...

Hope this helps !

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.