首页 > 其他 > 详细

位运算的“奇巧淫技”

时间:2019-08-13 13:15:17      阅读:90      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

技术分享图片

 

 

技术分享图片

 

 

 

 技术分享图片

 

 

#include<bits/stdc++.h>
using namespace std;

int getbits(int n)//统计(n)bin中的1的个数 
{
	int res=0;
	while(n)
	{
		res++;
		n=n&(n-1);
	}
	return res;
}

int cmp(int a,int b)//统计a,b中the number of different bits in the binary format of a and b. 
{
	return  getbits(a^b);	
} 

int main()
{
	int a,b;
	while(cin>>a>>b) cout<<cmp(a,b)<<endl;
	return 0;
}

  

 

位运算的“奇巧淫技”

原文:https://www.cnblogs.com/dragondragon/p/11340440.html

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