* Counts number of 1 bits in a 32 bit unsigned number.
* This method counts the number of bits set within the given
* integer. Given an n-bit value with k of those bits set, the
* efficiency of this algorithm is O(k) rather than the O(n) of
* an algorithm that simply looped through all bits counting non
* zero ones.
* @param x unsigned 32 bit number whose bits you wish to count.
* @return number of 1 bits in x.
* @author Dale King KingD@TCE.com KingD@TCE.com
public static int countBits3( int x )
int count = 0;
while ( x != 0 )
x &= x - 1;