LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

efficient bit stream parsing

Hi,

What is the most efficient way of doing bit stream parsing in labview. I am acquiring data from a pxi 6561 and it comes in as unsigned u16 arrays with each array element as a sample from the 6561. The 6561 is a 16 channel device for acquiring digital data. As the data comes in the elements of the u16 array look like as follows

b15, b14, b13, ..., b0 for each sample. I am converting this to strings to parse it. But creating a string multiplies the amount of memory used since each element of the array is becomes 16 * 1 bytes = 16 bytes since each bit in the u16 array element becomes one character of a string which is 8 bits. For an array with many elements such as 10^6 elements, this becomes memory intensive. Is there a more efficient way to do bit stream parsing in labview.

Thank you,

-Tim
0 Kudos
Message 1 of 4
(3,464 Views)

Tim,

Not sure why you are converting to strings - but that is a huge resource hog.  If you need to see certain bits, the most efficient way to di it is using bit masks to 0 the bits you are not interested in and then us shift operations to convert to a number if you need to.

An example would be if bits 3-5 represented a uint between 0-7, you would logical AND the16 bit word with 0000000000111000 binary.  Then use a logical shift to move bits 3-5 to bit positions 0-2.

Bitwise operations like these are very fast because they are done at the register level

Bill F

Message 2 of 4
(3,454 Views)

If you are interested in a 2d array of booleans, you could typecast the U16 into an array of booleans (make you sure you have 4.x conversion) right click on the type cast



A little background:
In LV 4.x and earlier an array of booleans were bit-wise in memory, each bit was one element.
After that they changed it to bytewise, each byte is one element.


Depending on you purpose this might be faster.
Another way might be AND-ing like Bill said, then do a conversion into U8. And then typecast it into an array of booleans (NOT 4.x style0) this works on one bit, because false is declared 0, and true non-zero.
Ton


See here

 
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!
Message 3 of 4
(3,432 Views)
 

The very first LV Challenge was the "Bit Twidler". See here.

http://zone.ni.com/devzone/cda/tut/p/id/5307 

There was plenty to learn in that challenge!

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 4
(3,412 Views)