在 java 中 2518379987 ^ 0 得到的是 2518379987
但是在 js 中我尝试着用 2518379987 ^ 0 运算得到结果 -1776587309
为什么会有这两种不同的结果呢?
1
ballshapesdsd 2019-02-22 17:39:28 +08:00
补码吧,变成有符号 int 了?
|
2
yukiww233 2019-02-22 17:42:02 +08:00
|
3
GPIO 2019-02-22 17:45:26 +08:00 1
int x=2518379987;
unsigned int x1=2518379987; int x2=x^0; unsigned int x3=x1^0; std::cout << x2 << " " << x3 << endl; 输出 -1776587309 2518379987 |
4
hahastudio 2019-02-22 17:50:28 +08:00
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
The operands of all bitwise operators are converted to signed 32-bit integers in two's complement format. |