cogmission cogmission - 1 year ago 91
Python Question

Get the same shift left in Python as Java

Specifically I want to take this number:

x = 1452610545672622396

and perform

x ^= (x << 21) // In Python I do x ^= (x << 21) & 0xffffffffffffffff

I want to get:
, which is what I get in Java

instead of:
, which is what I get in Python (which is what I don't want)

EDIT: In Java I do:

long x = 1452610545672622396;
x ^= (x << 21);

Answer Source

You can use 64bit signed int like java using ctypes.c_longlong, please see example below:

from ctypes import c_longlong as ll

x = 1452610545672622396

output = ll(x^(x<<21))

print output
print output.__class__
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download