파이썬
파이썬 16진수를 십진수 실수로 변환하기 python hex to double
행복햐
2017. 8. 18. 13:05
"python hex to double"을 사용하여 구글에서 검색하여 만든 코딩
#python 3.x
#http://stackoverflow.com/questions/3531723/unpack-from-hex-to-double-in-python
# value = 0.004732..... or "0x3F70624DDC71C71D"
value = ['\x1d', '\xc7', '\x71', '\xdc', '\x4d', '\x62', '\x73', '\x3f']
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)
print ( sign*2**exp*(1+mantissa*2**-52) )
참고: 16진수를 십진수 실수로 변화하는 웹사이트
http://www.binaryconvert.com/convert_double.html