For ordinary applications, you can use functions such as header files Stdlib.h and stdio.h,string.h, and then call the required itoa (), atoi (),
But for the Linux kernel, the functions in the C library are not available.
There is a corresponding implementation in this Linux kernel:
For atoi () use Simple_strtol (), Simple_strtoul () and other functions to replace;
For itoa (), use snprintf ().
Other related functions, to see/LIB/VSPRINTF.C.
Like what:
Simple_strtoul,simple_strtol,simple_strtoull,strict_strtoul,strict_strtol,strict_strtoull,strict_strtoll, vsnprintf,vscnprintf
In addition, for common character-related processing functions, they are in/lib/string.c:
STRNICMP,STRCASECMP,STRNCASECMP,STRCPY,STRNCPY,STRLCPY,STRCAT,STRNCAT,STRLCAT,STRCMP,STRNCMP,STRCHR,STRRCHR, Strnchr,strstrip,strlen,strnlen,strspn,strcspn,strpbrk,strsep,sysfs_streq
and memory-related action functions:
Memset,memcpy,memmove,memcmp,memscan,strstr,memchr
Source:
/*
const char *PTR The target string, the string to be converted
Char **end the position of the destination string, general padding null
cardinality of int base//convert String
Return value: An integer represented by a string
*/
unsigned long long int strtoull (const char *ptr, char **end, int base)
{
unsigned long long ret = 0;
if (Base > 36)
Goto out;
while (*PTR) {
int digit;
if (*ptr >= ' 0 ' && *ptr <= ' 9 ' && *ptr < ' 0 ' + base)
digit = *ptr-' 0 ';
else if (*ptr >= ' a ' && *ptr < ' a ' + base-10)
digit = *ptr-' A ' + 10;
else if (*ptr >= ' a ' && *ptr < ' a ' + base-10)
digit = *ptr-' a ' + 10;
Else
Break
RET *= Base;
ret + digit;
ptr++;
}
Out
if (end)
*end = (char *) ptr;
return ret;
}
Example:
int index = Simple_strtol ("12345", NULL, 10);
The converted integer is 12345