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 displays as 4294967294
I know FF should be the marker for - but is there a method in python that can just read the values directly or do I have to make my own method?
Thank you!
Edit: This is for Python 2.6. My program reads from binary data and I am just displaying it in hex to make it simpler. The program simply reads 4 bytes at a time and grabs values from those 4 bytes. It is just some of those values are negative and display the above numbers. I am also hoping someone can explain how Python interprets the binary data into a value so I can write a reverse protocol. Thank you!
I read from hex and convert to values through this method.
def readtoint(read):
keynumber = read[::-1]
hexoffset=''
for letter in keynumber:
temp=hex(ord(letter))[2:]
if len(temp)==1:
temp="0"+temp
hexoffset += temp
value = int(hexoffset, 16)
return value
It grabs 4 bytes, inverses the order, then converts the hex value into a int value. THe values I posted above are inverted already.