posted 24 years ago
Hi, Vineet.
A little rule that I use when I need to represent negative numbers in binary is
~i = -i-1.
That is, the bitwise inversion of "i" is equivalent to negative "i" less one.
In your example, you're looking for the binary representation of -192. Since -192 = -191-1, the following statement is true:
~191 = -192.
So if we can find the binary representation of 191, then invert all its bits, we will have the binary representation of -192.
This computation requires us to know which data type we are working with: since you didn't specify, I'll assume we are working with ints (32 bits).
191 = 2**7 + 2**5 + 2**4 + 2**3 + 2**2 + 2**1 + 2**0
+191 = 00000000 00000000 00000000 10111111
then
~191 = 11111111 11111111 11111111 01000000 = -192.
I hope this helps, Vineet.
Art