How can I create a single precision number given an ASCII HEX string in MATLAB 7.8 (R2009a)?

3 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Since the HEX2NUM only supports DOUBLE precision data, the following is a workaround for using only built-in functions to allow HEX2NUM type functionality to extent to SINGLE data.
% first create an example
str=num2hex(single(-pi));
% now convert the string of ascii HEX characters back into a single precsion number
n=typecast(uint32(hex2dec(str)),'single');
% note that eps(n) is on the order of the error for -pi-n

More Answers (0)

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!