321682!"#$%&'(10!")# 16 !"#$%&'10 !(")*+, #include <> #include <> #include <> #include <> #include <> #define CONVERT_ERROR 99 #define BASE 16 char HEX[BASE]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D',\ 'E','F'}; unsigned int hex2dec(char ch) { char c; if(islower(ch)) c=toupper(ch); else c=ch; for(int i=0;i<BASE;i++) { if(c==HEX[i]) return i; } return CONVERT_ERROR; } double hexchar2dec(char* str) { double dec=; unsigned int len=strlen(str); bool flag=true; http://hi./pengjun for(unsigned int i=0;i<len;i++) { if(hex2dec(str[i])==CONVERT_ERROR) { flag=false; break; } dec += hex2dec(str[i])*pow(BASE,len-1-i); } return flag==true?dec:0; } int main() { char ch[256]; cin>>ch; cout<<hexchar2dec(ch)<<endl; getchar(); return 0; } 8 !"#$%&'10 !(") #include <> #include <> #include <> #include <> #include <> #define CONVERT_ERROR 97 #define BASE 8 char OCT[BASE]={'0','1','2','3','4','5','6','7'}; unsigned int oct2dec(char ch) { if(!isdigit(ch) || ch<'0' || ch>'7') { return CONVERT_ERROR; } http://hi./pengjun for(int i=0;i<BASE;i++) { if(ch==OCT[i]) return i; } return CONVERT_ERROR; } double octchar2dec(char* str) { double dec=; unsigned int len=strlen(str); bool flag=true; for(unsigned int
32、16、8、2进制字符串转换为10进制数字 来自淘豆网m.daumloan.com转载请标明出处.