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-(N&1)-((N>>31)&1); will fix this case. On 2010-12-22 14:44, Saurabh Koar wrote: @Terence: I think the above fails fo

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 algogeek

Re: [algogeeks] bits groups

2010-12-21 Thread Terence
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

[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 ma

Re: [algogeeks] bits

2010-06-13 Thread jalaj jaiswal
hmm... for question number 1.. .. u can understand more easliy with the following examlple #include // 1. #include #pragma pack(1) struct value { int a; int bit3: 4; int bit4: 4; }; #pragma pack() int main() { struct value bit; printf("%d",sizeof(bit)); system("pause"); return

Re: [algogeeks] bits

2010-06-13 Thread Debajyoti Sarma
1. i think if the total no of bits is within no of bits in a int , the size will b same as int . here total bits 3 < 32 (bits in int according to gcc, in Turbo c its 16) so size of structure will be 4(in gcc), 2 (in TC) if total no of bits is 40 (suppose) than size will be 8(in GCC) , 4(in TC)

[algogeeks] bits

2010-06-13 Thread divya
tell the o/p of following with explanations 1. #include int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit; printf("%d\n",sizeof(bit)); return 0; } 2. #include int main() { struct value { int bit1: 1; int bit3: 4; int bit4: 4; } bit={1,2,2}; printf("%d %d %d\n",bit.bit1,bit.b

[algogeeks] bits required to convert A to B

2009-08-16 Thread richa gupta
Given two integers A & B. Determine how many bits required to convert A to B.how to write a function int BitSwapReqd(int A, int B); -- Richa Gupta (IT-BHU,India) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Alg