Jun 27, 2009

Given two integers A & B. Determine how many bits required to convert A to B. Write a function

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;
}

No comments:

Post a Comment