How to convert a file containing real numbers into binary/hexadecimal?
Show older comments
I want to convert whole file of real numbers having atleast 1000 data points into binary/hex using some function or program. Plz help
Accepted Answer
More Answers (2)
Azzi Abdelmalek
on 19 Jun 2016
Edited: Azzi Abdelmalek
on 19 Jun 2016
0 votes
You can use dec2bin and dec2hex function
1 Comment
Walter Roberson
on 19 Jun 2016
No, that only works for non-negative integers.
MEENU SAINI
on 19 Jun 2016
0 votes
3 Comments
Walter Roberson
on 19 Jun 2016
The outputs are correct for double precision numbers, but you happen to be looking for output for single precision numbers. Apply single() to the numbers and num2hex() the result. Alternately you can use something like
char(arrayfun(@(x) sprintf('0x%08x', typecast(single(x), 'uint32')), YourArray(:), 'Uniform', 0))
or
num2str(typecast(single(YourArray(:)),'uint32'), '0x%08x')
MEENU SAINI
on 20 Jun 2016
Walter Roberson
on 20 Jun 2016
https://www.mathworks.com/matlabcentral/newsreader/view_thread/30803
Categories
Find more on Data Type Conversion 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!