String Challenge

Please explain the logic of the convertToInt function step by step

hello @shreyasdaga

if 123 is the number then we can write this as 1 * 10^2 + 2 * 10 +3 right?
string to int function is doing the same thing.
if string is “123”
then first it is adding 3 to answer .[ (‘3’-‘0’) * 1 = 3]
and then it is adding 20 to the answer [ (‘2’-‘0’ )*10 = 20 ]
and then 100 [ (‘1’-‘0’)*100 = 100 ]
and the end result is 123.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.