qfedu-basic-level/day5/d1.cpp

23 lines
723 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 源码反码补码
#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;
}