Why is it useful to count the number of bits?

I have seen numerous questions about counting the number of bits in an input insert type of, but why is this useful?

For those looking for bit counting algorithms, see here:

+5
source share
4 answers

You can consider a string of bits as set, with 1 representing membership in the set for the corresponding element. Therefore, counting bits gives you population countdialing.

, . . wikipedia.org/wiki/Hamming_weight wikipedia.org/wiki/Hamming_distance.

+5

, . ( , , - .) , , , 1 .

, , , , .

0

, , , comp sci.

0

/ "".

, 1 , , , 1-.

countbits((x XOR (x-1)))-1;

, .

Let x =     00101100
Then x-1 =  00101011
x XOR x-1 = 00000111

3 , 2 1-

0

All Articles