C++输出数字二进制、十进制、八进制、十六进制1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include<iostream>
#include <bitset>
using namespace std;
int main() {
int num = -42;
cout << bitset<sizeof(num) * 8>(num) << endl;
cout << num << endl; //默认十进制输出
cout << hex << num << endl;
cout << oct << num << endl;
return 0;
}
输出:
11111111111111111111111111010110
-42
ffffffd6
37777777726