Cannot Read LabVIEW Binary Files in Other Applications

Updated Nov 21, 2022

Reported In

Software

  • LabVIEW Professional
  • LabVIEW Full
  • LabVIEW Base

Issue Details

I am using LabVIEW for Windows. When I write binary data to a file from LabVIEW and then try to read it back with a program written in another language, my data does not appear to be correct. I have already checked, and the program reading the data is reading the correct bytes for each field. How do I get LabVIEW to write a binary file that can be read in a C (or another language) program on Windows platforms?

Solution

 LabVIEW uses Big Endian format for its binary numbers, while most Windows programs use Little Endian format.

If you want to read the binary file using a Windows program you need to specify the byte order input on the Write Binary File VI to be little-endian.



For an example on how to write a file using proper endian representation, open the NI Example Finder under Help » Find Examples. Then navigate to Fundamentals » File Input and Output » Endian Considerations with Binary Files.vi

Additional Information

LabVIEW uses Big Endian, because that is what the MacOS uses, and LabVIEW was created first for the Macintosh.

In Big Endian format, the most significant byte (MSB) of a multi-byte number is written first, then the second MSB, and so on down to the least significant byte (LSB). However in Little Endian, it is reversed such that the LSB is written first, then the second LSB on up to the MSB.

For example:
  a U8 "1"a U16 "1"a SGL precision Number
LabVIEW:"BIG ENDIAN"(00000001)(00000000 00000001)(Byte4:Byte3:Byte2:Byte1)
(Win) C:"LITTLE ENDIAN"(00000001)(00000001 00000000)(Byte1:Byte2:Byte3:Byte4)

 The byte order can also be specified when using Flatten to String VI and Unflatten from String VI.