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

2 次查看(过去 30 天)
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