#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;
}
相关文章
- 11-25Cracking The Coding Interview 4.7_暂存
- 11-25"Coding Interview Guide" -- 括号字符串的有效性和最长有效长度
- 11-25"Coding Interview Guide" -- 翻转字符串
- 11-25"Coding Interview Guide" -- 仅用递归函数和栈操作逆序一个栈
- 11-25《Cracking the Coding Interview》——第13章:C和C++——题目6
- 11-25Cracking Digital VLSI Verification Interview 第二章
- 11-25《Cracking the Coding Interview》——第7章:数学和概率论——题目3
- 11-25Craking the Coding Interview 面试题:随机抽出子数列
- 11-25【Cracking the Code Interview(5th edition)】一、数组与字符串(C++)
- 11-25Cracking the coding interview--Q2.4