Method 1: sscanf ()
Function name: sscanf
Function: Format string input.
Usage: int sscanf (char * string, char * format [,argument, ...]);
The above format of %x is to format the string as 16 hexadecimal number.
Example:
# include & ltstdio.h & gt
void main()
{
char * p = " 0x 1a ";
int nValude = 0;
sscanf(p," %x ",& ampnValude);
printf("%d\r\n ",nValude);
}
Output:
26
Method 2: strtol ()
Function name: strtol
Function: Converts a string into an integer.
Usage: longstrtol (char * str, char * * endptr, intbase);
The cardinal number above is the decimal number we want to convert.
Example:
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
void main()
{
char * p = " 0x 1b ";
char * str
long I = strtol(p & amp; str, 16);
printf("%d\r\n ",I);
}
Output:
27