Let's say I have n bitmasks (n is arbitrary, probably a number from 9-25). The length of these bitmasks (which is equal for all of them) does not matter, but for the sake of an example, let's say we have 3 bitmasks of length 3:
b1: 1 0 0
b2: 1 1 1
b3: 1 0 1
I now want to map those 3 bitmasks (or n in a general case) to 4 (n + 1) other bitmasks, one for each possible number of occurrences. For this example, the resulting bitmasks should be:
0: 0 0 0
1: 0 1 0
2: 0 0 1
3: 1 0 0
- 0 has no bits set because no bit in the original bitmasks is set 0 times.
- 1 has the 2nd bit set because it is set exactly one time in the original set of bitmasks
- 2 has the 3rd bit set because it is set exactly 2 times in the original set of bitmasks
- 3 has the 1st bit set because it is set exactly 3 times in the original set of bitmasks
Now the question: Does anybody know a clever strategy to achieve this? The easiest attempt to do this is obviously going through each bit and counting the number of occurrences in the original bitmask set. However, I was wondering if there was some clever way of bit manipulation to keep track of all bits at the same time. Creating intermediate bitmasks is fine. The number of operations should of course be below the "naive" way outlined above. Any ideas?