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_SIZE = 8 * PHP_INT_SIZE ; $ count = array ( ) ; for ( $ i = 0 ; $ i < $ INT_SIZE ; $ i ++ ) $ count [ $ i ] = 0 ;