In Javascript when I do this
var num = 1; ~ num == -2
why does ~num not equal 0
in binary 1 is st
~ toggles the bits of the operand so
~
00000001
becomes
11111110
which is -2
Note: In javascript, the numbers are 32-bit, but I shortened it to illustrate the point.