Python expresses a number as a really large integer rather than a negative number

0

Is there a way to force python to treat a number based upon its sign?

E.g. 0xFFFFFFFF = -1 instead of 4294967295?

python
types
casting
asked on Stack Overflow Nov 22, 2020 by Austin Harrison

1 Answer

1

You can use ctypes.c_int32 for a signed 32 bit integer:

import ctypes
wrapped = ctypes.c_int32(0xFFFFFFFF)
print(wrapped) # c_int(-1)
print(wrapped.value) # -1
answered on Stack Overflow Nov 22, 2020 by Aplet123

User contributions licensed under CC BY-SA 3.0