LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UBYTE array to float?

Solved!
Go to solution

I'm fairly new to Labview, and haven't found an example of this on these forums.  Any help would be greatly appreciated!  

 

I'm reading in a character stream from a serial device, and I wish to convert a 4-byte string (or ubyte array) into a float value.  Is there a way to do this in labview?  

 

For example, I have the array { 0x4b, 0x1c , 0x90, 0x42 } = 0x4b1c9042 = a float value of 72.055260

 

I can do this in c by:

 

   char floatarray[] = {0x4b, 0x1c , 0x90, 0x42, 0x00}; 

   memcpy( &floatvalue, &floatarray, sizeof(float) ); 

   printf("\nMy float value is %f", floatvalue);  // would give 72.055260 for floatvalue

 

Is there a way to accomplish this in Labview? 

0 Kudos
Message 1 of 4
(3,267 Views)

Hi G,

 

typecast to SGL...(numeric -> data manipulation palette)

Message Edited by GerdW on 08-15-2009 12:31 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(3,258 Views)
Solution
Accepted by Mr. G

Note that if you're getting the string in that order then you will need to reverse the string first:

Message Edited by smercurio_fc on 08-14-2009 05:33 PM
Message 3 of 4
(3,253 Views)

Ah ha....  The trick is to reverse the string first!!!!!!  I was experimenting with typecasting before I posted, but didn't understand the values it was returning!!!!  Thank you, 
 
Mr. G 
0 Kudos
Message 4 of 4
(3,247 Views)