NI Home
Cart Cart | Help
Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Currently Being Moderated

Boolean Array to Binary File

VERSION 4

Created on: Mar 18, 2009 11:06 PM by BurtS - Last Modified:  Sep 12, 2009 8:01 AM by BurtS

Functional Description

This program demonstrates how to take a binary array, convert it to a byte array, and write this information to a binary file.  By default, LabVIEW will give each boolean in an array its own byte in the binary file.  Bit packing as done in this example allows for much more efficient memory usage.

 

 

Caveats and Additional Notes

This program assumes that the boolean array is one-dimensional.  When writing a multi-dimensional array to the file, you may want to write a true to the 'prepend array array or string size' option of the Write to Binary File.VI.  This will allow you to retrieve the proper array dimensions when reading from this file in the future.  Also, there is a Binary File to Boolean Array example found here to demonstrate how to perform the conversion in the opposite direction.

 

Boolean Array to Binary File 2.PNG

 

Downloads:
Average User Rating
(1 rating)




Christian Altenbach Christian Altenbach  says:

Code seems way too complicated. A reshape and simple FOR loop is all you need. Make sure to configure the output of "boolean array to number" for I8 or whatever you want.

 

Try e.g. something like the following:

 

BurtS BurtS  says in response to Christian Altenbach:

Thanks Altenbach,  this is definitely a better solution.  I have updated the example to reflect this solution.  Thanks for the input!

Christian Altenbach Christian Altenbach  says in response to BurtS:

Also don't forget that you can use typecast with the 4.x option to create packed boolean data. (while the order of the bits in each byte is reversed to the current solution, it would be fine if you do it on both sides of the transmission). Prior to LabVIEW 5, boolean arrays were stored packed, one bit per element. The current solution is OK, though.

More Like This

  • Retrieving data ...