title: Reading negative values from a file in python
body: <p>I am trying to read some negative values from a compressed file that has the hex values:</p>
  
  <ul>
  <li>FFFFFFFF, which should be -1, but displays as 4294967295</li>
  <li>FFFFFFFE, which should be -2, but displays as 4294967294</li>
  </ul>
  
  <p>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? </p>
  
  <p>Thank you!</p>
  
  <p>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!</p>
  
  <p>I read from hex and convert to values through this method.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>It grabs 4 bytes, inverses the order, then converts the hex value into a int value. THe values I posted above are inverted already.</p>