Code:
int htoi(char s[])
{
int i = 0; /* Iterate over s */
int n = 0; /* Built up number */
/* Remove "0x" or "0X" */
if ( s[0] == '0' && s[1] == 'x' || s[1] == 'X' )
i = 2;
while ( s[i] != '\0' )
{
int t;
if ( s[i] >= 'A' && s[i] <= 'F' )
t = s[i] - 'A' + 10;
else if ( s[i] >= 'a' && s[i] <= 'f' )
t = s[i] - 'a' + 10;
else if ( s[i] >= '0' && s[i] <= '9' )
t = s[i] - '0';
else
return n;
n = 16 * n + t;
++i;
}
return n;
}
Hi, I'm working through the problems in the K&R C book. Anyway I've read around and I can't understand this particular line?
Code:
t = s[i] - 'A' + 10;
I don't understand why the 10 is being added. Could anyone please explain?