Changing the Endian Form of Binary Numeric Data

Publish Date: Oct 11, 2011 | 11 Ratings | 3.55 out of 5 | Print | 4 Customer Reviews | Submit your review

Overview

This example demonstrates how to convert binary numeric data to an endian form that an application not created with LabVIEW can read.

LabVIEW stores numbers in big-endian form, with the most-significant byte first in memory. Mac and Sun applications usually expect the data to be of big-endian form, but Windows applications usually expect little-endian form, with the least-significant byte first. As a result, for a Windows application that requires little-endian form, you must explicitly swap the bytes in each number after you flatten or before you unflatten the data. If a Windows application requires little-endian two-byte binary data, you must swap the first byte with the second byte in each number before you write the data. 

The example VI (attached) shows five different methods for converting data from big-endian to little-endian form, or vice versa.

Note  Floating-point numbers in LabVIEW are IEEE-compatible, and the target application must be able to read such numbers. Single- and double-precision floating-point numbers are typically formatted appropriately, but extended-precision numbers, for which there are several formats in use, might not be.

Refer to the Application Note on LabVIEW Data Storage (linked below) for more information about endian forms.

LabVIEW 7.1 and Earlier

When you change the endian form of data, do not use the option of the LabVIEW Write File function that automatically writes a file header. This header is always of big-endian form. Instead, if you need a size header, write it explicitly before you write data to the file.

You must know the format the target application expects. For example, while an application might recognize a file created with the Write to I16 File or Write to SGL File functions with or without byte swapping, it might expect a type of header that these VIs do not supply. When you know exactly which format the application expects, use the appropriate features in LabVIEW to create such a file.

Back to Top

Customer Reviews
4 Reviews | Submit your review

Works OK  - May 11, 2015

I opened this in Labview 7.1 without any trouble.

Swapping endianess of mixed data types.  - Dec 11, 2013

The methods described in the example vi are useful if you are swapping single items or arrays of a single type. But if you need to swap a mixed data type such as a cluster, this will become extremely clunky. One way to handle this (which is certainly inelegant but a heck of a lot faster and automatic) is to write the cluster to a binary file using big endian and then read that binary back as little endian. To see the effect of this process, typecast your input cluster to an array of U8, then do the same thing with the data you read back from the little endian. You will see that all multi-byte data types have been swapped.

  - Oct 11, 2007

The downloadable example is saved with Labview 8.1 and thus cannot be opened with previous versions.

Incompatible Example  - Jun 8, 2006

The downloadable example does not work (cannot even be viewed) with either Labview 8.0 or 7.1.

View more reviews

Bookmark & Share


Downloads

Attachments:

big-little-endian-71.vi

Requirements


Ratings

Rate this document

Answered Your Question?
Yes No

Submit