Why is it that ~2 is equal to -3? How does ~ operator work?
~
Basically action is a complement not a negation .
Here x= ~x produce results -(x+1) always .
x = ~2
-(2+1)
-3