题解 | #两个整数二进制位不同个数#
两个整数二进制位不同个数
https://www.nowcoder.com/practice/16e48900851646c0b2c6cdef9d7ea051
#include <stdio.h> int main() { int a, b; while (scanf("%d %d", &a, &b) != EOF) { int n = 0; n = a ^b; int count = 0; while(n) { if(n%2 == 1)//算二进制最右边的1 count++; n >>= 1;//或者 n = n / 2; } printf("%d",count); } return 0; }