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 <richa.cs...@gmail.com>

>
> 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 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to