Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Please tell me how to convert the 1 QString number string into the 16 QString number string.
Please tell me how to convert the 1 QString number string into the 16 QString number string.
There are two main methods, which are actually the use of existing functions:

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