Bit manipulation

~0=-1 how ?
and how -1=11111111?
plz explain

Hi @tishya_goyal

A negative number can be represented in 2’s complement form. So to represent we take 1 in binary form in 8 bit system - 00000001. In order to convert a number to 2’s complement we first complement all it’s bit then add 1 to lsb. So 1’s complement of it is -> 11111110. Adding 1 to lsb we get 11111111.
Also 0 in bit is represented as 00000000. ~ sign signifies complement , so complementing each bit of 0 we get, 11111111 which we found out to be -1. Hence ~0 = -1.

Hope it Helps.

1 Like

okay…i got it…
Thanx

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.