import java.util.*;
public class Solution {
public int countBitDiff (int m, int n) {
// 按位异或运算,相同为0,不同为1
int c = m ^ n;
// 统计c的二进制形式中1的个数
int count = 0;
while ( c != 0) {
count += c & 1; // 末尾为1则计数
c = c >> 1; // 去除末尾数字
}
// 返回统计结果
return count;
}
}



京公网安备 11010502036488号