Convert decimal to IEEE 754 32 bit single precision floating point
20 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 27 Jul 2016
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 Comments
Kelvin Wong
on 27 Jul 2016
The data type of my input is uint8 and your function works perfectly. Thanks a lot for your help.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!