How can I create a single precision number given an ASCII HEX string in MATLAB 7.8 (R2009a)?
3 views (last 30 days)
Show older comments
I would like to create a single precision number given an ASCII hex string.
Accepted Answer
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
0 Comments
More Answers (0)
See Also
Categories
Find more on Cast and Quantize Data 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!