Jason S Jason S - 6 months ago 19x
Python Question

python 32-bit and 64-bit integer math with intentional overflow

What's the best way to do integer math in 32- and 64-bit, so that overflow happens like it does in C?

e.g. (65536*65536+1)*(65536*65536+1) should be 0x0000000200000001 in 64-bit math, and not its exact value (non-overflowing) 0x10000000200000001.


Just & the result with the appropriate 32- or 64-bit mask (0xffffffff or 0xffffffffffffffff).