Skip to content

Instantly share code, notes, and snippets.

@sungyongchoi
Last active July 8, 2016 07:01
Show Gist options
  • Save sungyongchoi/e4afa1132ee275815dc1507e858e926b to your computer and use it in GitHub Desktop.
Save sungyongchoi/e4afa1132ee275815dc1507e858e926b to your computer and use it in GitHub Desktop.
Read hexa data and covert to double in binary file
# python 3.x
from types import *
import struct
from struct import unpack
import numpy as np
import binascii
import functools
import sys
def hextodouble(value):
bytes = list( map(ord,reversed(value)) )
sign = (1,-1)[bytes[0]>>7]
exp = ((0x7f&bytes[0])<<4) + (bytes[1]>>4) - 1023
mantissa = functools.reduce(lambda x,y: (x<<8) + y, bytes[2:], bytes[1]&0xf)
return sign*2**exp*(1+mantissa*2**-52)
file = open('#1.wtf', 'rb')
file.seek(0x4EC)
rows = file.read(2)
file.close()
rows = int.from_bytes(rows,'little')
print( rows )
file = open('#1.wtf', 'rb')
file.seek(0x4708)
double = 8
total = 8*(rows+2)
points = file.read( total )
file.close()
x = []
y = []
for r in range( rows+1 ):
p= []
for c in range( 8 ):
i=8*r+c
s = points[i]
b = bytes([s]) # Convert byte to int
p.append ( b )
if c == 7 :
if (c == 7) :
if (r%2 == 0) :
x.append( hextodouble ( p ) )
else:
y.append( hextodouble ( p ) )
print( x,y )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment