Boise
Boise

Reputation: 195

How do I interpret two 32-bit unsigned integers as a 64-bit floating-point ("double") value?

My knowledge of matlab is very limited, so I'll use more general terms to explain my problem:

We have a recording system that samples variables in an embedded system in realtime, and delivers the recorded data as matlab files for analysis.

My problem is that if a recorded variable is a "double" (more specifically a 64-bit, IEEE 754-1985, floating point value), the result is delivered as two unsigned 32-bit integers, and I have no idea how to turn it back into a floating-point value in matlab.

For example, if I record the variable SomeFloat, which is a double, I will get the recorded data as two sets of data, SomeFloat1 and SomeFloat2. Both are unsigned, 32-bit integers. SomeFloat1 contains the 32 most significant bits of SomeFloat, and SomeFloat2 contains the 32 least significant bits.

I was hoping to find an existing function for converting it back do a double, I mean something like:

MyDouble = MyDreamFunction(SomeFloat1, SomeFloat2)

I have not been able to find MyDreamFunction, but being new to matlab, I'm not really sure where to look...

So, does anyone know of a simple way to do this?

Upvotes: 2

Views: 474

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

I think you want typecast (convert datatypes without changing underlying data):

>> x1 = uint32(7346427); %// example uint32 value
>> x2 = uint32(1789401); %// example uint32 value
>> typecast([x2 x1],'double')
ans =
  1.4327e-306
>> typecast([x1 x2],'double')
ans =
  3.7971e-308

Upvotes: 5

Related Questions