是否可以将 javascript 数字设置为 32 位而不是 64 位?
最佳答案
根据 JS 权威指南,如果您进行按位运算,数字会自动转换为 32 位:
The bitwise operators expect integer operands and behave as if those values were represented as 32-bit integers rather than 64-bit floating-point values. These operators convert their operands to numbers, if necessary, and then coerce the numeric values to 32-bit integers by dropping any fractional part and any bits beyond the 32nd. The shift operators require a right-side operand between 0 and 31. After converting this operand to an unsigned 32-bit integer, they drop any bits beyond the 5th, which yields a number in the appropriate range.
您所要做的就是对数字执行按位运算,例如将其与 0 进行或运算。您将得到相同的数字,但它将是 32 位。
关于javascript - 是否可以将 javascript 数字设置为 32 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23807508/