Convert decimal to IEEE 754 32 bit single precision floating point

조회 수: 24 (최근 30일)
Kelvin Wong
Kelvin Wong 2016년 7월 27일
답변: Kelvin Wong 2016년 7월 27일
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.

답변 (2개)

Walter Roberson
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.

Kelvin Wong
Kelvin Wong 2016년 7월 27일
The data type of my input is uint8 and your function works perfectly. Thanks a lot for your help.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by