How to convert a file containing real numbers into binary/hexadecimal?

1 visualizzazione (ultimi 30 giorni)
I want to convert whole file of real numbers having atleast 1000 data points into binary/hex using some function or program. Plz help

Risposta accettata

Walter Roberson
Walter Roberson il 19 Giu 2016
num2hex() is the routine to use to see the hex representation of the IEEE 754 bit pattern for float or double.

Più risposte (2)

Azzi Abdelmalek
Azzi Abdelmalek il 19 Giu 2016
Modificato: Azzi Abdelmalek il 19 Giu 2016
You can use dec2bin and dec2hex function

MEENU SAINI
MEENU SAINI il 19 Giu 2016
but there is some problem in the converted data. I have converted a file containing 1000 real numbers to hexadecimal using this function num2hex(). The real numbers are like:
-0.0128380000000000
-0.0142530000000000
-0.0080360000000000
-0.0120290000000000
-0.0136970000000000
-0.0268890000000000
-0.0320450000000000
-0.0295180000000000 & so on upto 1000.
--
The converted hex file is looking like:
bf8a4acf312b1b37
bf8d30ad46f587d7
bf80752da98676a7
bf88a2a90cd423d9
bf8c0d2c386d2ed8
bf9b88ca3e7d1351
bfa06833c60029f1
bf9e39f77292c493
--
but I think it should be like:
0xbc52567a
0xbc69856a
0xbc03a96d
0xbc451548
0xbc606962
0xbcdc4652
0xbd03419e
--
Is there any solution to this? Plz reply
  3 Commenti
MEENU SAINI
MEENU SAINI il 20 Giu 2016
Thank you Sir!! I have one more problem that after processing this converted data file, I need to convert this hex file back to real data file. So what function should I use? Plz help!
Walter Roberson
Walter Roberson il 20 Giu 2016
https://www.mathworks.com/matlabcentral/newsreader/view_thread/30803

Accedi per commentare.

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by