LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and writing binary files to arrays.

 

I am a relatively new user of LabVIEW and am having a hard time with binary files. I have a binary file and want to read the bits of the file into an array with entries 0 and 1s. I wish to modify this array and write it back to another binary file. The example Read binary file VI which came with the LabVIEW 2010 package outputs an array with value of the entries reaching upto 10.^308. I cannot understand the meaning of this. I want to get an array with just 0's and 1's from the binary file and write it back to another one. Please let me know of any possible solution. Thanks in advance!

0 Kudos
Message 1 of 13
(6,029 Views)

Can you give a little more explanation for what you are trying to do and why?

 

A binary file (like any other file) consists of a series of bytes.  It seems like you are asking to break that down farther into an array of bits.

 

I'm not sure what you are talking about with 10^308 which is an extremely large number.

 

If you want to read from one file and write to another, just do it like the examples show.

0 Kudos
Message 2 of 13
(6,023 Views)

Hi,

 

Thanks for replying!

Yes, I do need to break the bytes further down into bits, and need an array of bits (0s and 1s). I will need to flip some of the bits in this array (to simulate bit errors in actual wireless communication channels) and write the resulting array of bits into another binary file.

I saw the examples, but I feel that in my case, simply reading the data from one binary file and writing into another may not help because I need to do some bit flipping operations in the intermediate bit array.

In the example of reading binary files ( present in the labview example folder), the VI ouput an array, the entries of which were extremely large numbers (~10^308). I meant that.

 

0 Kudos
Message 3 of 13
(6,011 Views)

Hi raitexas,

  Can you post the binary file which you want to read in bytes?

 

Thanks and regards,

srikrishnaNF

Regards,
Srikrishna


0 Kudos
Message 4 of 13
(6,009 Views)

Hi,

 

Sure! Here is the file!

0 Kudos
Message 5 of 13
(6,003 Views)

Hi raitexas,

  Is there any reason particularly reading the file into an array?

 

 

 

Regards,
Srikrishna


0 Kudos
Message 6 of 13
(5,994 Views)

As I posted in my previous post, I would like to flip some of the bits randomly, so I need to read it into an array.

0 Kudos
Message 7 of 13
(5,987 Views)

 


@raitexas wrote:

 

 I want to get an array with just 0's and 1's from the binary file and write it back to another one. Please let me know of any possible solution. Thanks in advance!


 

What you can do is read the file as a string (don't convert EOL), then use a typecast to an array of booleans, right click on the typecast and select '4.x' data. (in LabVIEW 4.x and before an array of booleans were stored as actual bits).

Another (faster) option is to read the data as an array of U64/U32/U16/U8 and do the actions on the bit level (XOR,AND,NAND all work within these datatypes).

 

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!
0 Kudos
Message 8 of 13
(5,976 Views)

Hi Ton,

 

Thanks for replying. I tried something like your second suggestion. Yeah, I know XOR, AND etc works also on U8/U16 etc, however, I would like to interface a wireless channel simulator in the long run, and it accepts as input an array (of type double) with 0's and 1's. So, I was wondering if the binary file can be written into a bit array. Matlab has a command for file handling, doing these type of conversion (fread(fid,'ubit1')). I could output an array containing 0 and 1 using Matlab. I wanted to know if LabVIEW had similar type of file handling.

Secondly, I am having more trouble writing an array of 0 and 1's into a binary file. Please let me know if you have any idea regarding writing this bit array into the binary file.

 

Regards,

raitexas.

0 Kudos
Message 9 of 13
(5,947 Views)

Hi think you are still confusing some things here.

 

What does an array of 0's and 1's in a binary file look like?  If you opened it up in notepad, would it look like 11000110?  Those would be text characters and each bit they would represent would take up a byte.

 

If that is a set of bits, it would be 198 in decimal C6 in hex.  It would look like the AE character  Æ.

 

You can't read or write a bit at a time to a file.  PC's only work with bytes.  I'm not familiar with that matlab command, but I am sure it is still reading a byte and just giving you a bit out of it.

 

You are best off starting to think in terms of bytes and doing the manipulations in bytes.

 

You can use string to byte array, and use number to boolean array inside of a loop to convert to a 2-D boolean array where each column is the 8 bits for a character, and each row is a character.  You can do further array manipulations to reshape them into a 1-D array.  But you might have to play with the order of the bits as well.

 

But will all that array manipulation really help you solve what you are trying to do?  It will certainly take up at least 8 times the memory space, and possibly multiples of that with data copies.

 

0 Kudos
Message 10 of 13
(5,940 Views)