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:
importstruct
def readtoint(read):
returnstruct.unpack('<i', read)[0]
Example:
>>>readtoint('\xfe\xff\xff\xff')
-2
Post a Comment for "Reading Negative Values From A File In Python"