atoi() is able to translate a string of a number into an integer number. There are lots of tech to do, and here is showing some examples.
int my_atoi(char *p) {
int k = 0;
while (*p) {
k = k*10 + (*p) - '0';
p++;
}
return k;
}
10 times can be switched to bit-wise shift since bit-wise will use smaller instruction set which enables to reduce transistor in a system. Following shows of it.
int my_atoi(char *p) {
int k = 0;
while (*p) {
k = (k<<3)+(k<<1)+(*p)-'0';
p++;
}
return k;
}