如题 : 给定俩个十进制的整数,求解对应的二进制不同的位数有几位 测试数据 : 1999,2999 输出 : 7 思路 : 使用异或,异或运算相当于没有进位的加法运算,故该位为1表示对应位不同,对异或得到的值进行统计1的个数则得出结果 public int countBit(int m, int n) { int temp = m^n;//先将二者做异或运算,得到结果; int count = 0; while (temp != 0) { temp = temp & (temp-1);//每次与本身减1与运算,低位1就会去掉,直到全部1去掉 count ++; } return count; }