In C language, convert the string (decimal and hexadecimal) to a decimal number.
The following code extracts the hexadecimal and hexadecimal numbers of a string:
# Include
Typedef char TUINT8; typedef int TUINT32; TUINT32 Read_DecNumber (const TUINT8 * str); TUINT32 Read_HexNumber (const TUINT8 * str); int main (void) {int ret = Read_DecNumber ("1000"); int d = Read_HexNumber ("A"); printf ("converts the number in the string to A decimal number: % d \ n ", ret); printf (" convert the hexadecimal number in the string to the hexadecimal number: % d \ n ", d); return 0 ;} // convert the number in the string to the 10th digit TUINT32 Read_DecNumber (const TUINT8 * str) {TUINT32 value; if (! Str) {return 0;} value = 0; while (* str> = '0') & (* str <= '9 ')) {value = value * 10 + (* str-'0'); str ++;} return value ;} // convert the hexadecimal number in the string to the hexadecimal number TUINT32 Read_HexNumber (const TUINT8 * str) {TUINT32 value; if (! Str) {return 0;} value = 0; while (1) {if (* str> = '0') & (* str <= '9 ')) {value = value * 16 + (* str-'0');} else if (* str> = 'A ') & (* str <= 'F') {value = value * 16 + (* str-'A') + 10 ;} else if (* str> = 'A') & (* str <= 'F') {value = value * 16 + (* str-'A ') + 10;} else {break;} str ++;} return value ;}
Running result: