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

1 vue (au cours des 30 derniers jours)
Ivana
Ivana le 19 Sep 2012
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?
  1 commentaire
Azzi Abdelmalek
Azzi Abdelmalek le 19 Sep 2012
can you post a ample of your array

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 19 Sep 2012
Modifié(e) : Jan le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by