Skip to content Skip to sidebar Skip to footer

Replicating Javascript Bitwise Operation In Python

I'm trying to replicate a simple bitwise Javascript operation in Python. [Javascript] > 0xA867Df55 2825379669 > 0xA867Df55 ^ 0 -1469587627 [Python] >>> 0xA867DF

Solution 1:

How about converting from uint32 to int32.

importstructprintstruct.unpack('i', struct.pack('I', 0xA867Df55))[0]

OUTPUT

-1469587627

Or as @Ashwini suggests:

import ctypes
print ctypes.c_int(0xA867DF55 ^ 0).value

OUTPUT

-1469587627

Post a Comment for "Replicating Javascript Bitwise Operation In Python"