#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> int main() { int num1 = 1999; int num2 = 2299; int count = 0; int ret = num1^num2; //比特位不同异或后结果为1 while (ret) { ret = ret&(ret - 1); count++; } //将异或后的1输出,即有几个比特位不同 printf("%d", count); system("pause"); return 0; }
编程实现: 两个int(32位)整数m和n的二进制表达中, 有多少个位(bit)不同?
原创
©著作权归作者所有:来自51CTO博客作者be_better_的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
如何实现:两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同?
两个int(32位)整数 m和 n的二进制表达中,有多少个
#include 运算符 #define -
求出两个int(32位)整数m和n的二进制表达中,有多少bit位不同
编程实现两个int(32位)整数m和n的二进制表达中,有多少bit位不同
1.编程实现 两个int(32位)整数m 有多少bit位不同 -
【C语言】【笔试题】两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同
两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同? 输入例子:1999 2299输出例子:7
C语言 两个int(32位)整数m和n的二进制表 有多少个位(bit)不同 -
c语言:输入两个整数m和n,计算需要改变m的二进制表示中的多少位才能得到n
c语言:输入两个整数m和n,计算需要改变m的二进制表示中的多少位才能得到n
c语言 剑指offer 输入两个整数 -
求整数 在二进制表示中有多少个1的方法
一共有三种方法实现,具体看下面第一种第二种
#include ios 测试程序