1//16>>10
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6int fun(char *p);
7
8void main()
9{
10 char *pstr = "AE5"; //16进制的数
11 printf("hex: %s\n", pstr);
12 printf("dec: %d\n", fun(pstr));
13}
14
15//16>>10
16int fun(char *p)
17{
18 int j=0, k=1, iDec;
19
20 int n=strlen(p);
21
22 if(*p>='A' && *p<='E')
23 {
24 iDec = (*p-'A'+10);
25 }
26 else if(*p>='a' && *p<='e')
27 {
28 iDec = (*p-'a'+10);
29 }
30 else
31 {
32 iDec = *p-'0';
33 }
34
35 printf("char=%c, iDec=%-4d, n=%-2d\n",*p,iDec,n);
36
37 if (n == 1)
38 {
39 return iDec;
40 }
41 else
42 {
43 for (j=0; j<n-1; j++)
44 {
45 k*=16;
46 }
47 return iDec*k + fun(p+1);
48 }
49}