From ffb080d49fc0a9d022aeb14c9ed9804f3c4f9f44 Mon Sep 17 00:00:00 2001 From: flykhan Date: Tue, 20 Jun 2023 08:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=80=E4=B8=AA=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E7=AC=AC=20n=20=E4=BD=8D=EF=BC=88=E4=BB=8E=E5=8F=B3=E5=BE=80?= =?UTF-8?q?=E5=B7=A6=E6=95=B0=EF=BC=89=E7=BF=BB=E8=BD=AC=EF=BC=8C=E5=8D=B3?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=8E=9F=E6=9D=A5=E6=98=AF=200=EF=BC=8C?= =?UTF-8?q?=E5=8F=98=E4=B8=BA=201=EF=BC=9B=E5=A6=82=E6=9E=9C=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E6=98=AF=201=EF=BC=8C=E5=8F=98=E4=B8=BA=200=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day6/homework/h4.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 day6/homework/h4.cpp 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