源码反码补码

This commit is contained in:
flykhan 2023-06-16 16:33:40 +08:00
parent d545e83aa5
commit e5373892a1
1 changed files with 23 additions and 0 deletions

23
day5/d1.cpp Normal file
View File

@ -0,0 +1,23 @@
// 源码反码补码
#include <iostream>
#include <bitset>
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;
}