I have a known binary value, and I want to match it to other binary values

when a certain number of the same bits in both values are 1. For example,

if I have the known value 0111, I want it to match any other 4-bit value

that has at least 2 of the same bits set to 1. In other words, 0111 would

match:

0111

0110

0101

0011

1011

1101

1110

1111

0111 would NOT match:

0000

0001

0010

0100

1000

1001

1010

1100

Are there any efficient operators/expressions I can use to figure out the

number of matching bits between 2 values? I'm trying to figure out

something with the bitwise operators or some math operators. I'd like to

avoid iterating though and manually comparing every bit.

I know ahead of time the total number of bits to compare, and the number of

bits set to 1 in each of the two values I'll be comparing. The tough part

is finding the count of bits set to 1 that they have in common.

Thanks.