zero_group(N) {
  c=1-(N&1);       // For even N, zero groups is one more than 1 groups.
  while(N) {
    d = (N&(-N));  // Get the least significiant bit.
    N &= N+d;      // Clear the last 1-group bits
    c++;           // inc counter.
  }
  return c;
}

For more bit manipulations, refer to http://www-graphics.stanford.edu/~seander/bithacks.html.


On 2010-12-21 12:26, AEKME wrote:
How do you count the number of zero group bits in a number? group bits
is any consecutive zero or one bits, for example, 2 is represented
as ....0000000000000000010 has two zero bits groups the least
significant bit and the group starts after one.

Also, I am in a bad need for algorithms on bits manipulation if any
one has a reference, please share


--
You received this message because you are subscribed to the Google Groups "Algorithm 
Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to