=================================================
This article is Khler original, reproduced must ensure that this article complete and complete retain the original author information and the original link of this article
e- Mail: [email protected]
qq:23381103
MSN: [email protected]
=================================================
There are two main methods that are actually used for existing functions:
method 1:sscanf ()Function Name: sscanf
Function: Format input from a string
Usage: int sscanf (char *string, char *format[,argument,...]); The above format%x is the example of formatting a string into 16 digits: #include <stdio.h>
void Main ()
{
char* p = "0x1a";
int nvalude = 0;
SSCANF (P, "%x", &nvalude);
printf ("%d\r\n", nvalude); }
Output:
26
method 2:strtol ()Function Name: strtol
Function: Converts a string to a long integer
Usage: Long strtol (char *str, char **endptr, int base); The base above is what we're going to convert to a few decimal numbers.
Example: #include <stdio.h>
#include <stdlib.h>
void Main ()
{
char* p = "0x1b";
char* str;
Long i = Strtol (p, &str, 16);
printf ("%d\r\n", I); }
Output:
27 In fact, there is another way, is a string array initialized to 0~9~a~f, that is, a hexadecimal corresponding table, the corresponding table can be used to calculate the value of a hexadecimal string, but this hair is too troublesome, not recommended to use.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + hexadecimal string to numeric (numeric)