左移 Python 整数产生不正确的结果
Left shifting a Python integer yielding incorrect result
任何人都可以解释这个 Python 代码是怎样的:
print "bits_received:", bits_received
tmp = 0
print type(tmp)
tmp = (1 << bits_received)
print type(tmp)
print "tmp: 0x{:X}".format(tmp)
可能会产生这样的结果:
bits_received: 95
<type 'int'>
<type 'numpy.int64'>
tmp: 0x80000000
user2357112 正确:
bits_received: 88 <type 'int'>
bits_received: 95 <type 'numpy.int64'>
bits_received 变量的类型从 int 更改为 numpy.int64,通过添加另一个 numpy.int64 类型的变量。将其他变量包装在 "int(...)" 中解决了我的问题。
谢谢 user2357112!
任何人都可以解释这个 Python 代码是怎样的:
print "bits_received:", bits_received
tmp = 0
print type(tmp)
tmp = (1 << bits_received)
print type(tmp)
print "tmp: 0x{:X}".format(tmp)
可能会产生这样的结果:
bits_received: 95
<type 'int'>
<type 'numpy.int64'>
tmp: 0x80000000
user2357112 正确:
bits_received: 88 <type 'int'>
bits_received: 95 <type 'numpy.int64'>
bits_received 变量的类型从 int 更改为 numpy.int64,通过添加另一个 numpy.int64 类型的变量。将其他变量包装在 "int(...)" 中解决了我的问题。
谢谢 user2357112!