Re: [algogeeks] bits groups

2010-12-22 Thread Terence
@Saurabh: You are right. I was supposed there were infinite 0's on the left. For 32-bit number, the MSB should also be checked in addition to LSB. Change the first line to: c=1-(N1)-((N31)1); will fix this case. On 2010-12-22 14:44, Saurabh Koar wrote: @Terence: I think the above fails for

Re: [algogeeks] bits groups

2010-12-21 Thread Terence
zero_group(N) { c=1-(N1); // 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

Re: [algogeeks] bits groups

2010-12-21 Thread Saurabh Koar
@Terence: I think the above fails for 0X.Correct me if I m wrong. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] bits groups

2010-12-20 Thread AEKME
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 010 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