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;
}

 

December 2009
S M T W T F S
« Nov   Feb »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Follow Me

© 2011 Bread & Cup Suffusion theme by Sayontan Sinha