From e5373892a1b069bf81fc9882bc54e21296e8c01e Mon Sep 17 00:00:00 2001 From: flykhan Date: Fri, 16 Jun 2023 16:33:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E7=A0=81=E5=8F=8D=E7=A0=81=E8=A1=A5?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day5/d1.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 day5/d1.cpp diff --git a/day5/d1.cpp b/day5/d1.cpp new file mode 100644 index 0000000..62082c2 --- /dev/null +++ b/day5/d1.cpp @@ -0,0 +1,23 @@ +// 源码反码补码 +#include +#include + +using namespace std; + +int main() +{ + int z = -9; + cout << bitset<8>(z) << endl; + cout << bitset<8>(z >> 1) << endl; // 右移一位,符号位不变,左边补1 + cout << bitset<8>(z << 1) << endl; // 左移一位,符号位不变,右边补0 + cout << dec << z << endl; // 十进制 + cout << oct << z << endl; // 八进制 + cout << hex << z << endl; // 十六进制 + + signed int x = 20; + cout << bitset<8>(x) << endl; + cout << bitset<8>(x >> 1) << endl; // 右移一位,符号位不变,左边补0 + cout << bitset<8>(x << 1) << endl; // 左移一位,符号位不变,右边补0 + + return 0; +} \ No newline at end of file