int L=strlen(str)-1; bool Minus=(str[0]=='-'); int S=0; for(int i=L,mul=1;i>=Minus;i--,mul*=10) S+=((str[i]-48)*mul); S*=1-2*Minus;