var attr = ~'input,textarea'.indexOf( target.tagName.toLowerCase() ) ? 'value' : 'innerHTML' I saw it in an answer, and I've never seen it before. What does it mean?...

x <<= y (x = x << y) x >>= y (x = x >> y) x >>>= y (x = x >>> y) x &= y (x = x & y) x ^= y (x = x ^ y) x |= y (x = x | y) What do these different operators do?...

I've seen some performance critical javascript code, like the one on this project that makes extensive use of bitwise OR operations with 0. Ex: GameBoyAdvanceCPU.prototype.write8 = function (address, data) { address = address | 0; data = data |...

I can already convert 32bit integers into their rgba values like this: pixelData[i] = { red: pixelValue >> 24 & 0xFF, green: pixelValue >> 16 & 0xFF, blue: pixelValue >> 8 & 0xFF, alpha:...

I'm doing some bitwise manipulation in a project and I wonder if the built-in typed arrays might save me some headache and maybe even give me a bit of a performance gain. let bytes = [128, 129, 130, 131] let uint32 = (bytes[0] << 24) | (by...

I am trying to understand how bit-wise operation in JavaScript work, more specifically how the 32 bit number resulting from a bit-wise operation is converted back to a 64 bit JavaScript number. I am getting some strange results when setting the left...

I have 5 bit numbers like 10000 01000 00100 If only one bit is on in my calculation i have no problem. but if 2 bits are on then I want to select only the first on bit for example 10010 i want to treat it as 2 instead of the number 18 is ther...

I want to truncate a number in javascript, that means to cut away the decimal part: trunc ( 2.6 ) == 2 trunc (-2.6 ) == -2 After heavy benchmarking my answer is: function trunc (n) { return ~~n; } // or function trunc1 (n) { ...

I heard that you could right-shift a number by .5 instead of using Math.floor(). I decided to check its limits to make sure that it was a suitable replacement, so I checked the following values and got the following results in Google Chrome: 2.5 &g...

Edit: This question is out of date as the Polyfill example has been updated. I'm leaving the question here just for reference. Read the correct answer for useful information on bitwise shift operators. Question: On line 7 in the Polyfill exam...

©2020 All rights reserved.