Convert decimal to IEEE 754 32 bit single precision floating point
22 ビュー (過去 30 日間)
古いコメントを表示
I have the following decimal values. 190, 51, 39, 116. How can i convert this to IEEE 754 32 bit single precision floating point to get the value of -0.174955189228058. I need to use this as a matlab function block in Simulink, therefore i cannot use the conversion of hexadecimal to IEEE 754 32 bit single precision floating point matlab script.
0 件のコメント
回答 (2 件)
Walter Roberson
2016 年 7 月 27 日
function y = fcn(~)
%#codegen
t0 = zeros(1, 4, 'uint8');
t0 = uint8([190, 51, 39, 116]);
t0 = fliplr(t0);
y = zeros(1, 1, 'single');
y = typecast(t0,'single');
I used a ground as the input and sent the output to a display block, and it seems to work fine. Probably it could be simplified a little. I suspect, though, that you would be wanting to use the input signal, and I do not know what datatype your input signal would be.
0 件のコメント
Kelvin Wong
2016 年 7 月 27 日
The data type of my input is uint8 and your function works perfectly. Thanks a lot for your help.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!