LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read C++ 4-byte floats from binary in Labview

I am trying to extract information from a binary file.  In C++ the number I need to extract is a 4-byte float.  I can not get the right number to come out in Labview with any of the data types available, (single-precision, double precision, fixed point, long, byte, etc.)  I tried them all.  I'm using the read from binary file.vi.  Thanks.
0 Kudos
Message 1 of 5
(4,493 Views)
Hi Labview and C++ use different endian format. You have to swap the internal byte order in the float. The correct Labview type is SGL. Which Labview version do you use, as I think it is some functions that can handle this in newer Labview versions


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 2 of 5
(4,490 Views)
Well, if you have 4-byte floats then you should be using SGL. DBL is the wrong size, and the other datatypes just don't make any sense. Your most likely problem is endianness (i.e. byte order). If this file was written by another application you need to find out if it used little-endian or big-endian. LabVIEW uses big-endian by default. The Read Binary File can be set to specify the endianness to use.
0 Kudos
Message 3 of 5
(4,486 Views)

Yea, you're right.   The correct version is little-endian, whatever that means.  The biggest problem I had though, was not fixing the indicator to be the same as the control in the read from binary file.vi.  The right data type was single-precision format.

Thanks though for the speedy response.

0 Kudos
Message 4 of 5
(4,480 Views)

hilbert wrote:

Yea, you're right.   The correct version is little-endian, whatever that means.  The biggest problem I had though, was not fixing the indicator to be the same as the control in the read from binary file.vi.  The right data type was single-precision format.

Thanks though for the speedy response.


LabVIEW originates from the MAC which originally were big endian. Intel processors are little endian. In memory LabVIEW stores all data big-endian.

 

Here's some more detail.

 

Here's a question for debate:

What is the speed penalty for using big endian data on a little endian platform?

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 5 of 5
(4,465 Views)