Jason S Jason S - 2 years ago 158
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download