#include <stdio.h>
int c16toi10( char c );
int main( void )
{
    int n;
	char str[20];
	char *p;
	printf("正の16進数の入力 ==>");
	scanf("%s", str);
	
	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
		printf("ERROR\n");
	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;
}