具体来说,我想获取这个号码:
x = 1452610545672622396
并执行
x ^= (x << 21) // In Python I do x ^= (x << 21) & 0xffffffffffffffff
我想得到: -6403331237455490756
,这是我在Java中得到的
而不是:12043412836254060860
,这是我在Python中得到的(这是我不想要的)
编辑:在Java中我这样做:
long x = 1452610545672622396;
x ^= (x << 21);
最佳答案
您可以像使用 ctypes.c_longlong 一样使用 64 位签名 int ,请参阅下面的示例:
from ctypes import c_longlong as ll
x = 1452610545672622396
output = ll(x^(x<<21))
print output
print output.__class__
关于java - 在 Python 中获得与 Java 相同的左移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38872627/