Binary math on Number objects limited to 32 bits?

与世无争的帅哥 提交于 2019-12-24 12:27:35

问题


Consider the following code:

var combined:Number = Number(4294967296) | Number(2403025069);
var testLimit:Number = 6697992365;
trace("Combined is:", combined, "should be", testLimit);

Output is:

Combined is: -1891942227 should be 6697992365

Why?! I thought Number datatypes can hold 64 bit integers (okay- really 52-bit, but the numbers above are nowhere near that limit)


回答1:


From the documentation:

| bitwise OR Operator

Converts expression1 and expression2 to 32-bit unsigned integers, and places a 1 in each bit position where the corresponding bits of either expression1 or expression2 are 1.

...

The result is interpreted as a 32-bit two's complement number, so the result is an integer in the range -2147483648 to 2147483647.



来源:https://stackoverflow.com/questions/21747341/binary-math-on-number-objects-limited-to-32-bits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!