C++不支持直接使用二进制的数,只支持8,10,16三种进制的直接定义。
1.转16进制
#include <iostream>
using namespace std;
int main()
{
int x;
while(cin >> x)
cout << "Ox" << hex << x;
return 0;
}
2.转8进制
#include <iostream>
using namespace std;
int main()
{
int x;
while(cin >> x)
cout << "oct" << oct << x;
return 0;
}
3.默认转十进制,可以省略dec
#include <iostream>
using namespace std;
int main()
{
int x;
while(cin >> x)
cout << "dec" << dec << x;
return 0;
}