Cracking The Coding Interview 5.5

#include <iostream>
#include <vector>
using namespace std;
int getNum1(int N)
{
int num=0;
for (int i=0; i<32; i++)
{
int t = N&1;
if (t == 1)
{
num ++;
}
N = N>>1;
}
return num;
} void print(int p)
{
vector<int> v;
for (int k = 0;k<32; k++)
{
int t = p&1;
v.push_back(t);
p=p>>1;
}
for (int i = v.size()-1;i>-1; i--)
{
cout<<v[i]<<" ";
}
cout<<endl;
} int getDiff(int a, int b)
{
return getNum1(a^b);
}
int main()
{
int a = 8;
int b = 6;
print(a);
print(b);
cout<<getDiff(a,b)<<endl;
return 0;
}
上一篇:spring boot-mybatis全注解化(3)


下一篇:python suds 一坑