How to convert a single char into an int [duplicate]
You can utilize the fact that the character encodings for digits are all in order from 48 (for ‘0’) to 57 (for ‘9’). This holds true for ASCII, UTF-x and practically all other encodings (see comments below for more on this). Therefore the integer value for any digit is the digit minus ‘0’ (or 48). … Read more