//亲测可用#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <bitset>
using namespace std;
//unsigned long long Data;
unsigned int Data;
int ID[8] = {0,1,0,1,1,0,1,0};
int main()
{
int i;
//char s[100];
Data = ID[0];
for (i = 1; i < 8; i++)
{
Data = (Data << 1) | ID[i];
}
bitset<64>myset = Data;
cout << myset << endl;
printf("Data:%x\n", Data);
system("pause");
return 0;
}
本文展示了一个使用C++进行位操作的例子,通过数组初始化变量并利用bitset展示其二进制形式,最后输出十六进制表示。
5173

被折叠的 条评论
为什么被折叠?



