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

1 view (last 30 days)
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?

Accepted Answer

Jan
Jan on 19 Sep 2012
Edited: Jan on 19 Sep 2012
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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!