如果我的变量为8589934592
示例:
var a = (8589934592 | 0);
//a is 0
var b = (8589934591223 | 0);
//b is -777
var c = (85899345999 | 0)
//c is 79
var d = (858993459 | 0);
//d is 858993459
据我了解,d是正确的,但如果我尝试的数字大于858993459
但如果我有:例如
var a = (2147483647 | 0)
//a is 2147483647
var b = (2147483648 | 0)
//b is -2147483648
var c = (2147483649 | 0)
//c is -2147483647
我认为它就像一个负面的倒计时,我怎么能避免这个呢?
答案 0 :(得分:1)
你正在做一个按位操作(简单|:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR)
因此,这是使用32位signed int。
完成的也许你想加倍使用二进制逻辑运算符(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR)