title: Python : Convert hex value : from big-endian to little endian and then to decimal
body: <p>I am reading a file and extracting the data from the file, I could able to fetch the ASCII data and integer data.</p>
  
  <p>I am trying to convert 8 bytes of data from Big endian to Little endian and then to decimal value.</p>
  
  <p>Input file has this data </p>
  
  <blockquote>
    <p>00 00 00 00 00 00 f0 3f  </p>
  </blockquote>
  
  <p>This value has to be converted to 0x3ff0000000000000, so that hex_to_double(0x3ff0000000000000) returns value 1.0</p>
  
  <p>The code I am trying to convert the above value to little-endian and to decimal is</p>
  
  <pre><code># Get the Scalar value
  file.seek(0, 1)
  byte = file.read(8)
  hexadecimal = binascii.hexlify(byte)
  hexaValue = byte.hex()
  print(" hexadecimal 1 : %s"% struct.pack('&lt;Q', int(hexadecimal, base=16)))
  
  
  **# unable to convert the value to the int, so that it can be passed to **hex_to_double** function**
  
  # wrote this function to convert the int value to decimal value
  def hex_to_double(h):
      return struct.unpack('&lt;d', struct.pack('&lt;Q', h))[0]
  </code></pre>
  
  <p>Any suggestions shall be helpful.</p>