#include <stdio.h>
static int pow_count(int a,unsigned int x)
{
int num = 1;
unsigned int i;
if(x == 0){
return 1;
}
i = x;
while(i){
num = num*a;
i--;
}
return num;
}
int main() {
char num_x[256] = {0};
int num_d = 0;
int len = 0;
int i = 0;
int tmp = 0;
int a;
int status;
printf("please input hex :\n");
status = scanf("%x",&a);
while(status != 0 && status != EOF){
num_d = 0;
snprintf(num_x,sizeof(num_x),"%x",a);
len = strlen(num_x);
for(i=0;i<len;i++){
if(num_x[i] >= '0' && num_x[i] <= '9') {
tmp =(int)(num_x[i] - '0');
} else if(num_x[i] == 'a' || num_x[i] <= 'A'){
tmp = 10;
} else if(num_x[i] == 'b' || num_x[i] <= 'B'){
tmp = 11;
} else if(num_x[i] == 'c' || num_x[i] <= 'C'){
tmp = 12;
} else if(num_x[i] == 'd' || num_x[i] <= 'D'){
tmp = 13;
} else if(num_x[i] == 'e' || num_x[i] <= 'E'){
tmp = 14;
} else if(num_x[i] == 'f' || num_x[i] <= 'F'){
tmp = 15;
}
num_d += tmp * pow_count(16, len-1-i);
}
printf("the DEC transfer num is:%d\n",num_d);
printf("%d\n",num_d);
printf("please input the next hex num:\n");
status = scanf("%x",&a);
}
printf("invalid input!!!\n");
return 0;
}