Note:
c & (c - 1)
will clear the least significant bit in c. if we need to call this equation n times to let c becomes 0, there are n 1s in c!
int bitSwapRequired(int a, int b) {
// write your code here
int cnt = 0;
for (int tmp = a^b; tmp != 0; tmp = tmp & (tmp-1)) ++cnt;
return cnt;
}