|
#include <iostream>
|
|
#include <bitset>
|
|
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
char x = 0b01011011; // char 正好是八位
|
|
|
|
cout << "原值为: " << bitset<8>(x) << endl;
|
|
int n;
|
|
cout << "请输入要修改的位: ";
|
|
cin >> n;
|
|
x = x | (0x1 << n); // 作用: 将第 n 位设置为 1
|
|
cout << "修改后为: " << bitset<8>(x) << endl;
|
|
return 0;
|
|
} |