Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it useful to count the number of bits?

I've seen the numerous questions about counting the number of set bits in an insert type of input, but why is it useful?

For those looking for algorithms about bit counting, look here:

  1. Counting common bits in a sequence of unsigned longs
  2. Fastest way to count number of bit transitions in an unsigned int
  3. How to count the number of set bits in a 32-bit integer?
like image 984
KushalP Avatar asked Apr 13 '10 15:04

KushalP


People also ask

How do you count the number of bits in Java?

Java Integer bitCount() method The bitCount() method of Integer class of java. lang package returns the count of the number of one-bits in the two's complement binary representation of an int value. This function is sometimes referred to as the population count.

What does Brian Kernighan algorithm says?

The Brian Kernighan's Algorithm states that for an integer N :- (N) AND (N-1) is equivalent to N but with all the bits from and including the rightmost set bit (1) flipped.

How do you calculate bits in a byte?

A group of eight bits put together is known as a byte. A byte consists of 256 different combinations if you include the number 00000000 — all the binary numbers between 00000000 and 11111111.


1 Answers

You can regard a string of bits as a set, with a 1 representing membership of the set for the corresponding element. The bit count therefore gives you the population count of the set.

Practical applications include compression, cryptography and error-correcting codes. See e.g. wikipedia.org/wiki/Hamming_weight and wikipedia.org/wiki/Hamming_distance.

like image 156
Paul R Avatar answered Sep 27 '22 23:09

Paul R