diff --git a/day6/homework/h2.cpp b/day6/homework/h2.cpp new file mode 100644 index 0000000..0ceabcc --- /dev/null +++ b/day6/homework/h2.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 = x | (0x1 << n); // 作用: 将第 n 位设置为 1 + cout << "修改后为: " << bitset<8>(x) << endl; + return 0; +} \ No newline at end of file