Convert decimal to IEEE 754 32 bit single precision floating point

20 visualizzazioni (ultimi 30 giorni)
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.

Risposte (2)

Walter Roberson
Walter Roberson il 27 Lug 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.

Kelvin Wong
Kelvin Wong il 27 Lug 2016
The data type of my input is uint8 and your function works perfectly. Thanks a lot for your help.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by