什么呢字符串 - '0'做(string是一个char) [英] what does string - '0' do (string is a char)

查看:128
本文介绍了什么呢字符串 - '0'做(string是一个char)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么呢

while(*string) {
    i = (i << 3) + (i<<1) + (*string -'0');
    string++;
}

在*字符串-'0

the *string -'0'

它删除字符值还是怎么了?

does it remove the character value or something?

推荐答案

此减去到字符串指向字符的ASCII code 0 。因此, 0 - 0 为您提供 0 等和'9' - 0 为您提供 9

This subtracts from the character to which string is pointing the ASCII code of the character '0'. So, '0' - '0' gives you 0 and so on and '9' - '0' gives you 9.

整个循环基本上是心计手动的十进制整数的数值字符串中的字符串点。

The entire loop is basically calculating "manually" the numerical value of the decimal integer in the string string points to.

这是因为 I&LT;&LT; 3 等同于我* 8 I&LT;&LT; 1 等同于我* 2 (I&LT;&LT; 3)+(I&LT;&LT; 1) 等同于我* 8 + I * 2 我* 10

That's because i << 3 is equivalent to i * 8 and i << 1 is equivalent to i * 2 and (i << 3) + (i<<1) is equivalent to i * 8 + i * 2 or i * 10.

这篇关于什么呢字符串 - '0'做(string是一个char)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆