Problem Statment: Write a (regular or tail) recursive function that converts a valid hexadecimal string into a decimal value no longer than 64 bits.
"0x0" => 0
"0x1" => 1
"0xABCD" => 43981
"0x0" => 0
"0x1" => 1
"0xABCD" => 43981
int charTodec(char const ch){ if(ch>='a'&& ch<='f') return ch-'a'+10; if(ch>='A'&& ch<='F') return ch-'A'+10; else return ch -'0'; } unsigned long long int hexTodec(char const* str, unsigned long long result){ if(*str == '\0') return result; else{ result=result*16+charTodec(*str); return hexTodec(str+1,result); } }
Comments
Post a Comment