convertToInt() function

please explain what does the statement str[i]-‘0’ mean and why we are multiplying it with P to convert it to int?

Thanks