 <p>So what your code is doing is the following:</p> <p>x = '2', which represents 50 as a decimal value in the ASCII table. </p> <p>then your are basically saying:</p> <p>x = x - '0', where zero in the ASCII table is represented as 48 in decimal, which equates to x = 50 - 48 = 2. </p> <p>Note that 2 != '2' . If you look up 2(decimal) in the ASCII table that will give you a STX (start of text). This is what your code is doing. So keep in mind that the subtraction is taking place on the decimal value of the char.</p>