将十六进制转换为单精度 [英] Convert Hex to single precision
问题描述
num2hex $ 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屋!