Create a count array to store count of numbers that have a particular bit set . count [ i ] stores count of array elements with i - th bit set .
int INT_SIZE = 8 * sizeof ( unsigned int ) ; int count [ INT_SIZE ] ; memset ( count , 0 , sizeof ( count ) ) ;