I know that numbers in JavaScript are stored in IEEE-754 format. But when we use integers, particularly bitwise operators, they're represented as two's complement with 32 bits.
So -1
would be 0xFFFFFFFF
. But (-1).toString(2)
is -1
. And -1 >>> 31
is 1, that's right, but -1 >>> 32
must be 0
, however it's 4294967295
. And -1 << 32
must be 0
, but it is -1
.
Why do bitwise operations work in this way? And toString()
shows number with sign -
, why this minus is not in sign bit? Also why -1 >> 0
is -1
, but -1 >>> 0
is 4294967295
? I know what is the difference between >>
and >>>
, but the second operand is 0
, so I can't understand why these operations work in different ways.