public static int bitCount(final byte[] data) {
        int count = 0;
        for (final byte element : data) {
            byte bits = element;
            for (int j = 0; j < 8; j++) {
                if ((bits & 1) == 1) {
                    count++;
                }
                bits >>= 1;
            }
        }
        return count;
    }
public static int bitCount ( final byte [ ] data ) { int count = 0 ; for ( final byte element : data ) { byte bits = element ; for ( int j = 0 ; j < 8 ; j ++ ) { if ( ( bits & 1 ) == 1 ) { count ++ ; } bits >>= 1 ; } } return count ; }
Count the number of true bits.

@param data a target data
@return the number of true bits