Binary to floating point representation using IEEE-754
Show older comments
I am given a Character array of length 32 made of only zeros and ones and i want to convert in floating point representation using IEEE-754. Can any one help???? My string is '10101110101101011010010110101001'. and my code uptill now is
sign=binary(1);
exp=binary(2:9);
mantissa=binary(10:32)
subt=bin2dec(exp);
e=-127+subt;
num=0;
for i=1:length(mantissa)
num=mantissa(i)*2^(-i)+num;
end
1 Comment
Arslan Ahmad
on 22 Feb 2018
Accepted Answer
More Answers (1)
James Tursa
on 22 Feb 2018
Edited: James Tursa
on 22 Feb 2018
Any method you choose is going to have to make assumptions about bit/byte ordering and the handling of the special inf, nan, and denormalized bit patterns. The following method simply assumes that the char array bit pattern you have matches the machine you are currently using and accounts for these special patterns:
result = typecast(uint32(bin2dec(S)),'single');
The other methods shown in this thread that work with the sign, exponent, and mantissa bits directly do not account for these special bit patterns.
1 Comment
Anton Shishkin
on 12 Sep 2022
Thanks a lot
Categories
Find more on Language Fundamentals 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!