Why complement of 0 is -1?

186 Views Asked by At

I was learning about bitwise operators and I learnt that complement of 0 is 1 and 1 is 0. But when I tried using ~0 on IDLE, it printed -1 and when i typed ~1 it gave -2..

1

There are 1 best solutions below

0
Ixtiyor Majidov On
-1 is 0-1 => 00..00-00...01  = 1..11

So, as long as you consider some finite width (width is the size of integer or binary form you are using,4,8 ....),it is true that:

 00..00 =~11..11 

then, the following also be true:

~0=-1