#include #include #include #include /* * Return the numeric value represented by the hex digit c. */ struct assoc { char c; int v; }; struct assoc hexval[] = {{'0',0},{'1',1},{'2',2},{'3',3},{'4',4}, {'5',5},{'6',6},{'7',7},{'8',8},{'9',9}, {'a',10},{'b',11},{'c',12},{'d',13},{'e',14},{'f',15}, {'A',10},{'B',11},{'C',12},{'D',13},{'E',14},{'F',15}}; int getval (char c) { int i; for (i=0; i < sizeof(hexval); i++) if (hexval[i].c == c) return hexval[i].v; return 0; } int main () { int c; int val; while (1) { c = getchar(); val = 0; if (c == EOF) exit(0); while ((c != EOF) && (c != '\n') && isalnum(c)) { val = val*16+getval(c); c = getchar(); } printf("%d\n", val); if (c == EOF) exit(0); } return 0; }