Skip to content Skip to sidebar Skip to footer

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: -

Solution 1:

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

from ctypes import c_longlong as ll

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

printoutputprintoutput.__class__

Solution 2:

You might cause an overflow. Java long is 64 bit long while python has no size limit. Try using Long wrapper class of long. The Long object has also no limits (Well technicially everything has its limits...).

Post a Comment for "Get The Same Shift Left In Python As Java"