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