这行代码:
console.log((90000000000000|0).toString());
输出:
-1039687680 ( bin -111101111110000110000000000000 )
根据32-bit signed integer conversion,我期望:
/--discarded--\/---------significant----------\
10100011101101011000010000001111010000000000000 = 90000000000000
│
11000010000001111010000000000000 OR
00000000000000000000000000000000
================================
11000010000001111010000000000000 = -1107795968
sign/\------significant bits-------/
为什么我得到-1039687680而不是-1107795968?
最佳答案
如您所链接的文章中所述,它采用二进制补码格式。
负数11000010000001111010000000000000 xor 1加1等于
正11110111111000011000000000000000,1039687680
最终-1039687680获得了。