byte to float conversion

Solution Available

Aug 13, 2009
3 Posts

1  |  0  

Re: byte to float conversion

Is there a way to convert 4 bytes of raw data (byte array, string...) into a float?  Tried using a variant and VarChangeType but that does not seem to work properly.  Trying to avoid having to chop up the data and recalculate the floating point value from the standard.  Could make a dll in C but it should be possible using the ATE functions.

Any suggestions would be appreciated.

Thanks
Ryan

Albert Q.
Anaheim, CA

Aug 13, 2009
11 Posts

0  |  0  

Re: byte to float conversion

What is the content of the array or string? Is it a integer or a float? Can you provide example?

Thanks,
Albert

Aug 13, 2009
3 Posts

0  |  0  

Re: byte to float conversion

I am streaming data over a serial line from a controller.  The data is the raw representation of the floating point data on the controller.
So if I send a floating point "1" out of the controller, I would get a "0x3F800000" (according to IEEE-754)  so that can be read into either an array of 4 bytes, or a string or whatever I need to put it in.  I just need a native way of converting that raw data into the original floating point number.

In C you can do a memcopy(), or in C++...
floatingData = reinterpret_cast<float&>(*rawDataArray);

Thanks for the response

Albert Q.
Anaheim, CA

Aug 13, 2009
11 Posts

0  |  0  

Re: byte to float conversion

Use MemoryCopy to copy the raw data to a variable of type FLOAT:

For example,

f : Float
auc[ ] : Byte

MemoryCopy(&f, &auc[0], sizeof FLOAT)

Regards,
Albert

Aug 13, 2009
3 Posts

0  |  0  

Re: byte to float conversion

Thank you so much, that did it, for some reason I just could not find that command in the help file.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]