Given two integers A & B. Determine how many bits required to convert A to B. Write a function
int BitSwapReqd(int A, int B)
{
unsigned int count;
int diffnum = A ^ B;
for(count=0; diffnum; count++){
diffnum &= diffnum-1;
}
// here count is total no. of bit
return count;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment