Python2.7 IEEE 754字符串转浮点数
![](https://img-blog.csdnimg.cn/20210113112535462.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1ODAxNzg=,size_16,color_FFFFFF,t_70#pic_center)
想法其实很简单:
(1)取符号位: 对应str[0]
(2)取阶码:对应str[1:9]
(3)取尾码:对应str[9:]
(4)计算小数点位置
(5)根据小数点切分尾码,分别计算整数和小数部分
(6)特殊情况处理:0,NaN,无穷…
def ConvertExponent(strData):#阶码转整数
return int(strData,2)-127
def ConverComplementToFixedDecimal(fixedStr):#字符串转小数
count=1
num=0
for ch in fixedStr:
if ch=="1"