One of the things that I have noticed about bitwise operations in JavaScript is that it can be convenient for smaller values, but doesn’t always work for larger values. The reason this is the case is because bitwise operators will only work fully for operands which can be fully expressed in a 32-bit signed format. In other words, using bitwise operations will only produce numbers that are in the range of -2147483648 (-231) to 2147483647 (231 – 1). In addition, if one of the operands used is outside of that range, the last 32 bits of the number will be used instead of the specified number. Therefore, in order to represent a terabyte in JavaScript while using the left shift operator (<<), you would need to do something like the following: [code language="javascript"] (1 << 30) * (1 << 10) // same as Math.pow(2, 40) [/code] If you are not familiar with bitwise operators in JavaScript, I suggest taking a look at this page from Mozilla’s Developer Network.

Categories: BlogJavaScriptJScriptMath

Leave a Reply

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