3,881
社区成员
发帖
与我相关
我的任务
分享
//这个是有结果的,自己运行
//注意一下result.txt的路径
#include <iostream>
#include <fstream>
using namespace std;
inline void show_bitcount32(unsigned int x, ostream& o)
{
static char tb[][5] = {
"0000","0001","0010","0011",
"0100","0101","0110","0111",
"1000","1001","1010","1011",
"1100","1101","1110","1111",
};
static int format = 0;
x = x - ((x >> 1) & 0x55555555UL);
x = (x & 0x33333333UL) + ((x >> 2) & 0x33333333UL);
x = (x + (x >> 4)) & 0x0f0f0f0fUL;
x += x >> 8;
x += x >> 16;
o << tb[x & 0x3f] << '\t';
if (!(++format%8)) o << endl;
}
int main()
{
fstream result;
result.open("result.txt", ios::out);
for (unsigned int i = 0; i < 0x200; ++i)
for (unsigned int j = 0; j < 0x200; ++j)
show_bitcount32(i^j, result);
result.close();
return 0;
}
#include <iostream>
using namespace std;
void show_bitcount32(unsigned int x)
{
static char tb[][5] = {
"0000","0001","0010","0011",
"0100","0101","0110","0111",
"1000","1001","1010","1011",
"1100","1101","1110","1111",
};
x = x - ((x >> 1) & 0x55555555UL);
x = (x & 0x33333333UL) + ((x >> 2) & 0x33333333UL);
x = (x + (x >> 4)) & 0x0f0f0f0fUL;
x += x >> 8;
x += x >> 16;
cout << tb[x & 0x3f] << '\t';
}
int main()
{
for (unsigned int i = 0; i < 0x400; ++i)
for (unsigned int j = 0; j < 0x400; ++j)
show_bitcount32(i^j);
return 0;
}