count number of zero group bits

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.


  1. zero_group(N) {
    int c,d=0;
    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;
    int main()
    return 0;


Post a Comment

Popular posts from this blog