Convert Two 16-Bit Unsigned Integers Into a 32-Bit Floating Point Number in LabVIEW

Updated Dec 1, 2023



  • LabVIEW

I received a pair of 16-bit unsigned integers that need to be converted into a 32-bit float. I tried sending the array to a type cast set to a 32-bit float (single) but it was not returning the correct data. How do I convert these two numbers into a 32-bit single floating point number?

The two 16-bit numbers provide the upper and lower halves of the 32-bit number. The following steps break down the attached VI.
  1. 16-bit numbers need to be joined using the Join Number function to create a 32-bit integer.
  2. Depending on the format your data and any other manipulations you would like to do, you may need to use the Swap Words function to obtain the correct value.
  3. You can then set the integer is then sent to the Type Cast function to designate the correct format representation.
  4. Set the data type to be cast to by wiring in a Numeric Constant to the top of the Type Cast function. Next, right-click on the Numeric Constant, go to Representation, and select SGL.
The picture below shows a simple example of how to do the conversion using arbitrary data. Keep in mind you may not need to use the Swap Words function depending on your data format. We only show it below to demonstrate how to use it.

Additional Information

This operation is not necessary if you are using the Modbus IO Server since it already handles this case with the use of F addressing. See the Using Modbus I/O Servers manual for more information on how to do so. The floating point value may have to be swapped depending on your device. See the How to Swap Registers for Modbus Floating Point Values article for details on more information on this topic.