#include
int BitSwapReqd(int A, int B);
{
int tmp=1, count=0;
while(A || B)
{
if(A&1 != B&1)
count++
A=A>>1;
B=B>>1;
}
return count;
}
int main()
{
int a,b;
printf("Enter the Value of A & B\n");
scanf("%d%d",&a,&b);
printf("these no of bits required to convert from A to B = %d
\n",BitSwapReqd(a
xor and count the number of bit set ...
On Mon, Aug 17, 2009 at 11:21 AM, Pramod Negi wrote:
> i guess XORing A and B and count the no of set bits will do.
>
>
> On Sun, Aug 16, 2009 at 11:09 PM, richa gupta wrote:
>
>>
>> Given two integers A & B. Determine how many bits required to convert
>
Sorry for 1st solution thr i dod one mistake now this one is rite one...
#include
int BitSwapReqd(int A, int B);
{
int tmp=1, count=0;
while(A || B)
{
if(A&1 != B&1)
count++
A=A>>1;
B=B>>1;
}
return count;
}
int main()
{
int a,b;
printf("Enter the Value of A & B\n");
scanf("%d%d",&a,&b);
printf
#include
int BitSwapReqd(int A, int B);
{
int tmp=1, count=0;
while(A || B)
{
if(A&1==B&1)
count++
A=A>>1;
B=B>>1;
}
return count;
}
int main()
{
int a,b;
printf("Enter the Value of A & B\n");
scanf("%d%d",&a,&b);
printf("these no of bits required to convert from A to B =
%d\n",BitSwapReqd(a,b));
yup this will be also rite
On Mon, Aug 17, 2009 at 11:21 AM, Pramod Negi wrote:
> i guess XORing A and B and count the no of set bits will do.
>
> On Sun, Aug 16, 2009 at 11:09 PM, richa gupta wrote:
>
>>
>> Given two integers A & B. Determine how many bits required to convert
>> A to B.how to w
Somehow like that should work.
int a, b;
int c = a ^ b; // ^ - XOR, now c has selected bits only at positions of
swapping
int i =0;
while(c){ //count bits of c
c = c & (c-1);
i++;
}
return i;
Oleg Šelajev
(+372 5518336)
2009/8/16 richa gupta
>
> Given two integers A & B. Determine how many
__bitcount(a ^ b), or use bitset<32>
or
int x=0;
int y=a^b;
while(y) {x++;y&=y-1;}
return x;
2009/8/17 Pramod Negi
> i guess XORing A and B and count the no of set bits will do.
>
>
> On Sun, Aug 16, 2009 at 11:09 PM, richa gupta wrote:
>
>>
>> Given two integers A & B. Determine how many bits r
i guess XORing A and B and count the no of set bits will do.
On Sun, Aug 16, 2009 at 11:09 PM, richa gupta wrote:
>
> 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)
>
> >