Reading Negative Values From A File In Python
I am trying to read some negative values from a compressed file that has the hex values: FFFFFFFF, which should be -1, but displays as 4294967295 FFFFFFFE, which should be -2, but
Solution 1:
Use the struct module:
import struct
def readtoint(read):
return struct.unpack('<i', read)[0]
Example:
>>> readtoint('\xfe\xff\xff\xff')
-2
Solution 2:
Post you file reading code to get the perfect answer. But answer to your question is almost certainly here:
Post a Comment for "Reading Negative Values From A File In Python"