Buffer and serial input

In ASCII, all the digit characters are in order, and in the range 0x30 to 0x39. This is intentional. Subtracting 0x30 from the character will give you the value of the digit. Adding 0x30 from a value will give you the appropriate digit (assuming values 0-9).

The C language shortcuts this, so you can type '0' to refer to the 0x30 value. It makes it quite readable: an expression (ch - 'A') tells you how far into the alphabet a character is, from 0 to 25; an expression (ch - '0') tells you the numeric value of a digit character. To convert upper to lowercase, ch = ch + ('a'-'A'). Etc.