Python
3 << 29
# 1610612736
3 << 30
# 3221225472L
JavaScript
3 << 29
// 1610612736
3 << 30
// -1073741824
为什么 JavaScript 位运算左移会输出负数?
1
geelaw 2018-07-01 20:14:37 +08:00 1
搜索 javascript left shift
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators Bitwise operators treat their operands as a sequence of 32 bits (zeroes and ones). ... Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values. ... Signed 32-bit integers The operands of all bitwise operators are converted to signed 32-bit integers in two's complement format. |
2
mooncakejs 2018-07-01 20:15:57 +08:00
应该是 python 为什么不是负数吧
|
3
MiffyLiye 2018-07-01 20:20:50 +08:00 1
|
4
MiffyLiye 2018-07-01 20:22:01 +08:00 1
而 Python 里整数是无限长的
|