kkltlb的个人空间 https://blog.eetop.cn/libinforever [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

matlab中实现 IEEE754浮点数 与 一般十进制数之间 互相转换的方法 ...

已有 2362 次阅读| 2020-12-2 12:46 |系统分类:其他| matlab, IEEE754, 浮点数, 十进制数转换

%2020/12/2 11:42:31
clc
format long


% IEEE754 to dec
a = '40800000'
a = dec2bin(hex2dec(a),32)
M = bin2dec(a(10:32))
E = bin2dec(a(2:9))
x = (-1)^a(1)*(1 + M*2^-23)*2^(E-127)


% dec to IEEE754

result = cos(x)

if(result<0)
S = '1'
else
S= '0'
end

result = abs(result)

i = 0
while(result<1)
result = result * 2
i = i+1
end

j = 0
while(result>2)
result = result/2
j = j+1
end

E = i + j
if(j == 0)
E = -E
end
E = E+127
E = dec2bin(E,8)
result
M23 =dec2bin(floor((result-1)*2^23),23)
r = [S,E,M23]
dec2hex(bin2dec(r))


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 2

    评论
  • 275

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-6 07:44 , Processed in 0.014110 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部