How to convert a file containing real numbers into binary/hexadecimal?
Afficher commentaires plus anciens
I want to convert whole file of real numbers having atleast 1000 data points into binary/hex using some function or program. Plz help
Réponse acceptée
Plus de réponses (2)
Azzi Abdelmalek
le 19 Juin 2016
Modifié(e) : Azzi Abdelmalek
le 19 Juin 2016
0 votes
You can use dec2bin and dec2hex function
1 commentaire
Walter Roberson
le 19 Juin 2016
No, that only works for non-negative integers.
MEENU SAINI
le 19 Juin 2016
0 votes
3 commentaires
Walter Roberson
le 19 Juin 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
le 20 Juin 2016
Walter Roberson
le 20 Juin 2016
https://www.mathworks.com/matlabcentral/newsreader/view_thread/30803
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!