qfedu-basic-level/day6/homework/h3.cpp

17 lines
368 B
C++

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