4 ms·
Why is the shift direction the inverse of C ? Is this an error ? It would be a pretty big mistake.
by chmike 14y ago
Why is the shift direction the inverse of C ? Is this an error ? It would be a pretty big mistake.
- jonny_eh 14y agoIt's definitely a typo.
- drostie 14y agoJS 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.