math - Python: unsigned 32 bit bitwise arithmetic -
trying answer post solution deals ip addresses , netmasks, got stuck plain bitwise arithmetic.
is there standard way, in python, carry on bitwise and, or, xor, not operations assuming inputs "32 bit" (maybe negative) integers or longs, , result must long in range [0, 2**32]?
in other words, need working python counterpart c bitwise operations between unsigned longs.
edit: specific issue this:
>>> m = 0xffffff00 # netmask 255.255.255.0 >>> ~m -4294967041l # wtf?! want 255
you can mask 0xffffffff
:
>>> m = 0xffffff00 >>> allf = 0xffffffff >>> ~m & allf 255l
Comments
Post a Comment