#include <stdio.h>
int c16toi10( char c );
int main( void )
{
int n;
char str[20];
char *p;
n = 0;
p = str;
if( c16toi10( *p ) != -1 )
n += c16toi10( *p++ );
while( c16toi10( *p ) != -1 )
{
n <<= 4;
n += c16toi10( *p++ );
}
if( *p == '\0' )
printf("%s(16) = %d(10)\n", str
, n
); else
return 0;
}
int c16toi10( char c )
{
int rtn;
if('0' <= c && c <= '9')
rtn = c - '0';
else if('A' <= c && c <= 'F')
rtn = c - 0x37;
else if('a' <= c && c <= 'f')
rtn = c - 0x57;
else
rtn = -1;
return rtn;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBjMTZ0b2kxMCggY2hhciBjICk7CmludCBtYWluKCB2b2lkICkKewogICAgaW50IG47CgljaGFyIHN0clsyMF07CgljaGFyICpwOwoJcHJpbnRmKCLmraPjga4xNumAsuaVsOOBruWFpeWKmyA9PT4iKTsKCXNjYW5mKCIlcyIsIHN0cik7CgkKCW4gPSAwOwoJcCA9IHN0cjsKCWlmKCBjMTZ0b2kxMCggKnAgKSAhPSAtMSApCgkJbiArPSBjMTZ0b2kxMCggKnArKyApOwoJd2hpbGUoIGMxNnRvaTEwKCAqcCApICE9IC0xICkKCXsKCQluIDw8PSA0OwoJCW4gKz0gYzE2dG9pMTAoICpwKysgKTsKCX0KCWlmKCAqcCA9PSAnXDAnICkKCQlwcmludGYoIiVzKDE2KSA9ICVkKDEwKVxuIiwgc3RyLCBuKTsKCWVsc2UKCQlwcmludGYoIkVSUk9SXG4iKTsKCXJldHVybiAwOwp9CgppbnQgYzE2dG9pMTAoIGNoYXIgYyApCnsKCWludCBydG47CglpZignMCcgPD0gYyAmJiBjIDw9ICc5JykKCQlydG4gPSBjIC0gJzAnOwoJZWxzZSBpZignQScgPD0gYyAmJiBjIDw9ICdGJykKCQlydG4gPSBjIC0gMHgzNzsKCWVsc2UgaWYoJ2EnIDw9IGMgJiYgYyA8PSAnZicpCgkJcnRuID0gYyAtIDB4NTc7CgllbHNlCgkJcnRuID0gLTE7CglyZXR1cm4gcnRuOwp9