#include <stdio.h>
#include <stdlib.h>
int Print_no(int a,int b){
int arr[32] = { 0 };
int brr[32] = { 0 };
int i = 0;
int count = 0;
while (a > 0){
arr[i++] = a % 2;
a /= 2;
}
i = 0;
while (b > 0){
brr[i++] = b % 2;
b /= 2;
}
for (int j = 0; j < 32; j++){
if (arr[j] != brr[j]){
count += 1;
}
}
return count;
}
int main(){
int a = 2;
int b = 8;
printf ("%d\n",Print_no(a, b));
system("pause");
return 0;
}
编程实现: 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同? 输入例子 : 1999 2299 输出例子 : 6
猜你喜欢
转载自blog.csdn.net/weixin_43508555/article/details/84312620
今日推荐
周排行