# Double类型浮点数和IEEE754双精度格式互相转换的实现方式

Double转IEEE754双精度
function TransData = Double2IEEE754_Bin(DoubleData)
%%暂未提供对非规格数的支持
if DoubleData0
Sign = 0;
Exponent = dec2bin(0,11);
Fraction = dec2bin(0,52);
else
if DoubleData<0 %确定符号位
Sign = ‘1’;
else
Sign = ‘0’;
end
Data_Normalized = abs(DoubleData); %求绝对值
Exp = 0;
if Data_Normalized<1
while(Data_Normalized<1) %根据>1和<1分情况讨论
Data_Normalized = Data_Normalized * 2;
Exp = Exp - 1;
end
else
while(Data_Normalized>=2)
Data_Normalized = Data_Normalized/2;
Exp = Exp + 1;
end
end
Exponent = dec2bin(Exp+1023,11);
%Fraction = dec2bin(floor((Exponent-1)*2^52),52);
Fraction = dec2bin(round((Data_Normalized-1)*2^52),52);
end
TransData=[Sign,Exponent,Fraction];
end
IEEE754转Double类型
function DataOut = IEEE754ToDouble_Bin(DataIn)
Fraction = bin2dec(DataIn(13:64));
Exponent = bin2dec(DataIn(2:12));
Sign = DataIn(1);
if Exponent
0 && Fraction==0
DataOut = 0;
else
DataOut = (-1)^Sign*(1 + Fraction*2-52)*2(Exponent-1023);
end
end

07-28 151
04-21 766
07-05 1万+
12-01 1254
11-01 1259
01-14 3170
05-21 540
12-09 9051
07-17 3191
04-11 1075
04-10 3083

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

a18271623106

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。