read csv file and convert 'double' to binary

7 visualizaciones (últimos 30 días)
je heo
je heo el 8 de Oct. de 2020
Comentada: Walter Roberson el 12 de Oct. de 2020
f = csvread('S21.csv',double=>binary);
I read .csv file in 'double'
ex) f(1,1) = 1.5111
I want to convert it to binary, 010101010,
no data loss as possible as.
How can I do???
Thank you for your coperation

Respuestas (1)

Ameer Hamza
Ameer Hamza el 8 de Oct. de 2020
See dec2hex(): https://www.mathworks.com/help/matlab/ref/dec2hex.html or num2hex(): https://www.mathworks.com/help/matlab/ref/num2hex.html if you want to use IEEE-754 format for conversion.
  4 comentarios
je heo
je heo el 12 de Oct. de 2020
thank you for your answer.. ^^
Walter Roberson
Walter Roberson el 12 de Oct. de 2020
Note that the above is just one representation of 1.5111, and that it is not to be interpreted as something like
00000101.11000101100011110011000101110111001011011111100000111111
You get closer to that kind of representation with
reshape(dec2bin(typecast(swapbytes(1.5111), 'uint8'),8).', 1, [])
ans = '0011111111111000001011010111011100110001100011111100010100000101'
but this again is not to be interpreted as a binary fraction, at least not without careful examination.
The first bit is the sign bit. The next 11 bits are the exponent, with a bias of 1022. The remaining 52 bits are a binary fraction with an implied "1." in front of it.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by