Did you know that the bitwise operators always return 32-bit (signed) integers? If you don’t believe me, test out the following examples for yourself:

alert(~~Math.pow(2, 31)); // -2147483648
alert((Math.pow(2, 30) - 1) << 2); // -4
alert(7.5 & 14.5); // 6
alert((Math.pow(2, 32) + 64) >> 3); // 8
alert(Math.pow(2, 31) | Math.pow(2, 31)); // -2147483648
alert(Math.pow(2, 33) ^ 7); // 7
Categories: BlogJavaScriptJScriptMath

Leave a Reply

Your email address will not be published. Required fields are marked *