atoi in java using charAt

char digit = (char)(tmp.charAt(i) – ‘0’);

In the ascii table, characters from '0' to '9' are contiguous. So, if you know that tmp.charAt(i) will return a character between 0 and 9, then subracting 0 will return the offset from zero, that is, the digit that that character represents.

Leave a Comment