#include
#include <Windows.h>
using namespace std;
int main(void) {
//位与 &
cout << "6 & 3 =" << (6 & 3) << endl;
//位或 |
cout << "6 | 3 =" << (6 | 3) << endl;
//位非 ~
unsigned char s= ~6;
cout << (int)s << endl;
//异或 ^
cout << "6 ^ 3 =" << (6 ^ 3) << endl;
//把一个整数的的最低4位设置为0110
int The_integer; //整数
cout << "请输入一个整数:";
cin >> The_integer;
//把后4位清零
The_integer = The_integer & (~15);
//把后4位设为0110
The_integer = The_integer | 6;
cout << "The_integer=" << The_integer << endl;
system("pause");
return 0;
}
cout << "请输入一个整数: " << endl;
cin >> x;
//把x的最低4位清0
x = x & (~15);
//把x的最低4位设置为0110
x = x | 6;
cout << “x=” << x << endl;