LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find 0 in a binary integer array

Hi,

 

I have a U16 array . The array size is 250000000

The format of each element is as below:

 

0000 1111 1111 1111 = 4095   ,  each 1 is  for 1 site.  This means all 12 sites passed

 

 

Let's say element 20000 is : 1011 1111 1111   : this means site 11 failed at step 20000

 

Now I would like to know what is the fastest way to search through all 2500000000 elements and find the first 0 ( if there is any ) for each site.

I have the following code that does this work but it is really time consuming . Please let me know if you suggest a better way

 

1.png

 

 

 

 

0 Kudos
Message 1 of 8
(4,001 Views)
Put the second loop inside the first. If fault ia found activate the conditional exit for the two loops.
0 Kudos
Message 2 of 8
(3,975 Views)

A_1.png

 

I don't see how I could do this faster.

0 Kudos
Message 3 of 8
(3,963 Views)

Hi tintin,

 

find the first 0 ( if there is any ) for each site.

I would use ouadji's suggestion and improve it by changing the constant used for the AND operation: It should contain just one single TRUE bit for the "site" you want to check!

check.png

All you need to do now is to call that snippet in a loop using the loop iterator as input for "site"… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(3,949 Views)

You have to make some benchmarks to determine which one is faster but this is another solution.

 

First NOGO.png

 

AND : keep only bit corresponding to a site

Search 1D Array : find first equal to 0

0 Kudos
Message 5 of 8
(3,943 Views)

GerdW posted his answer while I was editing mine and I saw I only after posting it.

0 Kudos
Message 6 of 8
(3,934 Views)

Where does the array come from?

 

It is safe to say that you won't be able to do any of this in LabVIEW 32bit, so I am assuming you are using 64bit LabVIEW.

 

If a failure is a relatively rare event,  it might be worth to only retain the failed elements, their index, and their value. It seems redundant to create gigabytes of output arrays where most elements are identical. You also might find a solution that does not need any green arrays.

 

0 Kudos
Message 7 of 8
(3,923 Views)

my solution is wrong  Smiley Frustrated ...  GerdW's solution is better. (dito for the JB's solution)

 

@ tintin_99 : " .... and find   the first 0   ( if there is any ) for each site. "

 

 

 

 

0 Kudos
Message 8 of 8
(3,882 Views)