首页 > 编程语言 > 详细

C++求2进制01不同的位数

时间:2015-05-01 10:40:34      阅读:286      评论:0      收藏:0      [点我收藏+]
#include <iostream>
using namespace std;
int Grial(int x,int y)
{
	int count  = 0;
	while(x!=0 || y!=0)
	{
		if( ((x&0x1) ^ (y&0x1)) )
		count++;
		x>>=1;
		y>>=1;
	}
	return count;
}
int main()
{
	cout<<Grial(2,15)<<endl;
	return 0;
}

C++求2进制01不同的位数

原文:http://blog.csdn.net/liuhuiyan_2014/article/details/45418073

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!