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

前端 未结 2 1008
忘了有多久
忘了有多久 2021-01-04 03:48

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 0x0000000200000

2条回答
  •  灰色年华
    2021-01-04 04:22

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

提交回复
热议问题