I have an Excel spreadsheet with 3 columns, where each column contains some random numbers. I am going to find out how many numbers in the first column and second column have a non-zero output from BITAND.
For example, assuming two columns A, B
A B
1 0
2 64
4 8
8 7
16
- 0 and 64 in B have no single bit "1" in common with any number in A.
- Number 8 in B have common bit 1 with the 8 in A.
- Number 7 in B have common bit 1 with number 1, 2, 4 in A.
Therefore, there are total of 4 pairs of numbers with non-zero BITAND result.
I find that Excel's BITAND does not support operation on a range of cells and therefore I am using a very inefficient method to do the work. Assuming the first column has 100 numbers and the second column has 55 numbers.
- I first fix one number in the second column and have each number in the first column
BITANDwith that number, which will generate a new column of 100 numbers. - Repeat the same procedure with the 1st column and the next number in the second column until all numbers in the second number looped.
- That will generate a total of 55 additional columns each have 100 results of
BITAND. - I then count the total number of non-zero entries.
I wonder if there is any better method instead of macro that will help to reduce the work since I may have more than 200 numbers per column in the future.
PS a sample Excel with my solution could be downloaded at enter link description here


