Example Code

Convert Binary Text file to a Numeric Array

Code and Documents

Attachment

Download All

Introduction

This VI shows how to read a text file with binary values, and set the appropriate binary bit in a number, then convert these values to an array of integers.  The input text file must contain a 2D array of numbers with 3 columns.The values in the first column correspond to the array index of the number in question.  The second column corresponds to the bit position of the number to be set or reset according to the value in column 3. If a bit position is not referenced, it will automatically be 0.

For example, the following data is in a text file:

0    0    0

0    1    1
0    2    1
1    1    0
1    2    0

2    0    1
2    1    0
2    2    1

The first entry (index 0) of the output array should be 0 * 2 ^ 0 + 1 * 2 ^ 1 + 1 * 2 ^ 2 = 6.

The second entry (index 1) of the output array should be 0 * 2 ^ 0 + 0 * 2 ^ 1 + 0 * 2 ^ 2 = 0.

The third entry (index 2) of the output array should be 1 * 2 ^ 0 + 0 * 2 ^ 1 + 1 * 2 ^ 2 = 5.

Binary Text File to Numeric Array Front Panel.jpg

Binary Text File to Numeric Array Block Diagram.jpg

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors