Determine the number of bits required to convert integer A to integer B
Example
Given n = 31, m = 14,return 2
(31)=(11111)
(14)=(01110)
class Solution {
/**
*@param a, b: Two integer
*return: An integer
*/
public static int bitSwapRequired(int a, int b) {
int count = 0;
int a_xor_b = a ^ b;
while (a_xor_b != 0) {
++count;
a_xor_b &= (a_xor_b - 1);
}
return count;
}
};