#include <iostream>
int count_different_bits(const unsigned int& a,
const unsigned int& b)
{
unsigned int c=a^b;
int count=0;
while(c)
{
c&=(c-1);
++count;
}
return count;
}
int main(int argc,char* argv[])
{
int a=5;
int b=10;
std::cout<<count_different_bits(a,b)<<std::endl;
return 0;
}
编程之美课后题:求得两个正整数A和B的二进制表示有多少位不同
最新推荐文章于 2022-01-24 22:33:32 发布