3 ms·
JS defines three bitwise shifts which work the way C works on signed int32's: [ 1 << 30 === Math.pow(2, 30), 1 << 31 === -Math.pow(2, 31),
by drostie 14y ago
JS defines three bitwise shifts which work the way C works on signed int32's:
[
1 << 30 === Math.pow(2, 30),
1 << 31 === -Math.pow(2, 31),
0xf0000000 >>> 1 === 0x78000000,
0xf0000000 >> 1 === 0x78000000 - Math.pow(2, 31)
];
// ==> [true, true, true, true]
As pointed out elsewhere in this thread there is one exception to this rule:
0xf0000000 >>> 0 === 0xf0000000;
// ==> true
In other words, right shifting is always unsigned.