diff --git a/day6/homework/h4.cpp b/day6/homework/h4.cpp new file mode 100644 index 0000000..91f0df6 --- /dev/null +++ b/day6/homework/h4.cpp @@ -0,0 +1,17 @@ +#include +#include + +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; +} \ No newline at end of file