您的位置:首页 > 其它

5.6 Conversion

2015-10-29 05:23 246 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  BitMani