递归 16进制转10进制


//16>>10
#include 
#include 
#include 

int fun(char *p);

void main()
{ 
 char *pstr = "AE5"; //16进制的数
 printf("hex: %s\n", pstr);
 printf("dec: %d\n", fun(pstr));
}

//16>>10
int fun(char *p)
{
 int j=0, k=1, iDec;

 int n=strlen(p);

 if(*p>='A' && *p<='E') 
 {
  iDec = (*p-'A'+10);
 }
 else if(*p>='a' && *p<='e') 
 {
  iDec = (*p-'a'+10);
 }
 else
 {
  iDec = *p-'0';
 }

 printf("char=%c, iDec=%-4d, n=%-2d\n",*p,iDec,n);

 if (n == 1)
 {
  return iDec;
 }
 else 
 {
  for (j=0; j

Comments are closed.