digit contains the ASCII value of the digit. So if digit=='1' then the value of digit is 49 (you can find these numbers at various places, e.g. http://en.wikipedia.org/wiki/ASCII ). '0' is 48, so digit-'0' is 1, so we have converted '1' to 1.

sum=sum*10+digit, that just builds the number up as we encounter more digits.
So at '1', sum=0*10+1=1. At '2', sum=1*10+2=12. At '3', sum=12*10+3=123.
So for each digit we encounter we multiply sum by 10 and add the new digit.