what does this do
while(*string) {
i = (i << 3) + (i<<1) + (*string -'0');
string++;
}
the *string -‘0’
does it remove the character value or something?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This subtracts from the character to which
stringis pointing the ASCII code of the character'0'. So,'0'–'0'gives you0and so on and'9'–'0'gives you9.The entire loop is basically calculating “manually” the numerical value of the decimal integer in the string
stringpoints to.That’s because
i << 3is equivalent toi * 8andi << 1is equivalent toi * 2and(i << 3) + (i<<1)is equivalent toi * 8 + i * 2ori * 10.