运算符有很多种。
下面是一个按位运算的小例子
#include "stdafx.h"
#include "iostream"
#include "string"
#include "bitset"
using namespace std;
int main()
{
cout << "please input a bool numbers : " << endl;
bool inputnumber1 = false;
cin >> inputnumber1;
bool inputnumber2 = false;
cin >> inputnumber2;
bitset<8> InputBits1(inputnumber1);
bitset<8> InputBits2(inputnumber2);
cout << "inputnumber1 in binary is " << InputBits1<<endl;
cout << "inputnumber2 in binary is " << InputBits2<<endl;
bitset<8> InputBitsAnd = (inputnumber1&inputnumber2);
bitset<8> InputBitsOR = (inputnumber1|inputnumber2);
bitset<8> InputBitsXOR = (inputnumber1^inputnumber2);
cout << "InputBitsAnd in binary is " << InputBitsAnd<<endl;
cout << "InputBitsOR in binary is " << InputBitsOR<<endl;
cout << "InputBitsXOR in binary is " << InputBitsXOR<<endl;
system("pause");
return 0;
}
运行结果如下
注意:
1 按位运算时要运用头文件 #include bitset
2 xor异或与or不同的是只有两个不相同时才为1,or只要有一个为True,输出的结果为true.