Python casts the code long to int

  • 2020-04-02 09:44:18
  • OfStack

After python2.4, if the value of an int is out of range, it will not overflow, but is internally converted to a long.
Oneself wrote a function, barely can use, for your reference.


import sys
def LongToInt(value):
    assert isinstance(value, (int, long))
    return int(value & sys.maxint)

After testing, the results are consistent on 32-bit and 64-bit.


Related articles: