标签:hex space lang ima octal ios ring printf 转换
#include<iostream>
using namespace std;
int main(){
string s;
cin >> s;
cout << "Hex: 0x" << s << endl;
int dec = 0, oct = 0;
for(int i = 0; i < s.size(); i ++)
dec = dec * 16 + (isalpha(s[i]) ? s[i] - ‘A‘ + 10 : s[i] - ‘0‘);
printf("Decimal: %d\n", dec);
int t = 1;
while(dec){
int x = dec % 8;
oct = x * t + oct;
dec /= 8;
t *= 10;
}
printf("Octal: %04d", oct);
return 0;
}
标签:hex space lang ima octal ios ring printf 转换
原文地址:https://www.cnblogs.com/tomori/p/13680195.html