MATLAB: How to read each bit in a data of class “double”

bitsdouble

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?

Best Answer

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.