将十六进制转换为单精度 [英] Convert Hex to single precision

查看:586
本文介绍了将十六进制转换为单精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



num2hex 我很努力于在Matlab中将32位十六进制表达式转换为单个精度数字。 $ c>函数适用于两者。例如,

 
>> b = 0.4

b =

0.400000000000000

>> class(b)

ans =

double

>> num2hex(b)

ans =

3fd999999999999a

>> num2hex(single(b))

ans =

3ecccccd

然而,这种方式并不适用。 hex2num 函数 only 将十六进制表达式转换为双精度。所以,

 
>> b = 0.4

b =

0.400000000000000

>> num2hex(single(b))

ans =

3ecccccd

>> hex2num(ans)

ans =

3.433227902860381e-006

位十六进制。有没有一种方法来执行这种转换?

解决方案

内置<$ c似乎不可能$ c> hex2num ,但幸运的是,您可以获得一个精确版本的 hex2num hexsingle2num )这里: http://www.mathworks.com/matlabcentral/fileexchange/6927-hexsingle2num


I'm struggling with converting a 32-bit hex expression into a single precision number in Matlab.

The num2hex function works fine for both. For example,

>> b = 0.4

b =

   0.400000000000000

>> class(b)

ans =

double

>> num2hex(b)

ans =

3fd999999999999a

>> num2hex(single(b))

ans =

3ecccccd

However, this does not work the other way around. The hex2num function only converts hexadecimal expression into doubles. So,

>> b = 0.4

b =

   0.400000000000000

>> num2hex(single(b))

ans =

3ecccccd

>> hex2num(ans)

ans =

    3.433227902860381e-006

Matlab simply pads zeros to make it a 64-bit hex. Is there a way to perform this conversion?

解决方案

It doesn't seem to be possible with the built-in hex2num, but fortunately you can get a single precision version of hex2num (hexsingle2num) here: http://www.mathworks.com/matlabcentral/fileexchange/6927-hexsingle2num

这篇关于将十六进制转换为单精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆