Hello all,

Given two 32-bit numbers, I want to decide which number has more bits set.
And what the difference in the number of bits set is. So for example, if
Num1=1110000...011 and Num2= 0000011...001, I'm trying to write an efficient
function numBitsSet() that returns 2 if Num1 has 2 more bits set than Num2
and -2 if Num2 has 2 more bits set than Num1. In this case, it'll return 2.

Yes, I can do this easily by looping through the two numbers and storing a
counter etc etc. But I need an efficient way to do this - I'm trying to do
this by using a combination of xors or something. Please email me if you
have any suggestions.

Thank you.
anukool.

Reply via email to