写出一个程序,接受一个十六进制的数值字符串,输出该数值的十进制字符串。
例如1:
输入:0xA
输出:10
例如2:
输入:0xB1
输出:177
STL库:十进制转别的进制
char s2[100];//转化2进制
int value=10;
itoa(value,s2,2); //第三个参数 代表进制
std::bitset(转2进制),std::oct(转8进制),std::dec (转10进制),std::hex(转16进制)
int GetValue(char* strInValue, char* strOutValue) { if ( NULL== strInValue || NULL== strOutValue|| *strInValue == '\0') return -1; char *wrong; ltoa((strtol(strInValue, &wrong, 16)), strOutValue, 10); if (wrong != NULL) return -1; else return 0; }