# Convert a non-digit char to int

Hi,

While browsing the code for my project, I found the following snippet:
if(isdigit(chararray[0]))
val = atoi(chararray);
else
val = chararray[0] - 'a' + 10;

I am not sure I understand the code under the else part.

Can anyone throw some light?

TIA
PV

• every character on the keyboard has an ascii value (google for "ascii chart") and there are 256 possible values. For example, the letter 'a' has an ascii value of 97. If chararray[0] == 'a', then the formula you posted will yield 97 - 97 + 10 which is just 10. If chararray[0] == '#' then it will yield 35 - 97 + 10 which is -52.

http://www.lookuptables.com/
• : every character on the keyboard has an ascii value (google for "ascii chart") and there are 256 possible values. For example, the letter 'a' has an ascii value of 97. If chararray[0] == 'a', then the formula you posted will yield 97 - 97 + 10 which is just 10. If chararray[0] == '#' then it will yield 35 - 97 + 10 which is -52.
:
: http://www.lookuptables.com/
:
It looks like a code snippet to convert a hexadecimal digit to decimal.

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl