필터 지우기
필터 지우기

How to read each bit in a data of class "double"?

조회 수: 2 (최근 30일)
Ivana
Ivana 2012년 9월 19일
I am reading data that is being sent through the UDP protocol, with the function fread. I currently am reading a matrix with 19 elements. However, I want to read separately all the singular bits of the last element of the matrix. So is there a way I can chop the double precision of only the last element and read it in uint64? The matrix, say it's called A, has a size of [19 1], and if I use the conversion uint64(A(19)) it will only give me one number back. But I really need to read the singular bits... Any suggestions?

채택된 답변

Jan
Jan 2012년 9월 19일
편집: Jan 2012년 9월 19일
What about this:
firstPart = fread(fid, 18, 'double');
lastPart = fread(fid, 1, 'uint64');
Or:
data = fread(fid, 19, 'double');
last = typecast(data(19), 'uint64');
Calling uint64(X) is equivalent to cast(X, 'uint64'). While this converts the type but keeps the value as exact as possible, TYPECAST does not change the bits.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by