read csv file and convert 'double' to binary

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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 8일

0 개 추천

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

je heo
je heo 2020년 10월 8일
편집: je heo 2020년 10월 8일
thank you for your answer
but i want only binary form which has '0100010101' .
The example you posted first had 9 bits, and this version has 10 bits. How many bits of output are you looking for?
reshape(dec2bin(typecast(1.5111, 'uint8'),8).', 1, [])
ans = '0000010111000101100011110011000101110111001011011111100000111111'
je heo
je heo 2020년 10월 12일
thank you for your answer.. ^^
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2020년 10월 8일

댓글:

2020년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by