I couldn\'t wrap my head around this:
def expr(a):
return ~(a ^ 0xFFFFFFFF), a ^ 0xFFFFFFFF, ~a, a
print(expr(0xFFFFFFFF))
print(expr(1))
print(expr(0))
p
0xFFFFFFFF
is a large number; it's the hexadecimal representation of 232-1. Python's ints are represented internally as a linked list of C longs, allowing theoretically unbounded size. Bitwise XOR (^
) in Python uses zero values for the bits more significant than those you've given, so the net result is that only the lower 32 bits are flipped, resulting in behavior that diverges from what you get in C, where there are only 32 bits and the net result is that 'all' the bits are flipped.