/ * Writer HTOI (s), convert a string of 16 credit (containing optional prefix 0x or 0x) into equivalent integer values. The numbers that are allowed in the string include: 0 ~ 9, a ~ f, a ~ f. * / # Include #include #include int htoi (char * head) {int Number = 0, bit = 0 CHAR * S = head; if (head == null) exit (-1); while (* s! = '/ 0') s ; s -; / * s pointing to the last character * / while (s! = Head) {// bit, s if (* s> = '0' && * s <= '9') {Number = ((* s-'0 ') * (Signed Int) POW (16, bit) ); S -; bit ; contract;} if (* s> = 'a' && * s <= 'f') {Number = (* S-'A ' 10) * (Signed int) POW 16, bit)); s -; bit ; Continue;} if (* s> = 'a' && * s <= 'f') {Number = ((* s-'a ' 10) * (Signed INT) POW (16, bit)); s -; bit ; Continue;} Break;} if (* s == 'x' || * s == 'x') {s -; if (* s == 0 '&& s == HEAD) Return Number; Else Return -1;} IF (s == HEAD) Return Number; return -1;} int main (void) {char * a = "0x"; int B = HTOI (a); Printf ("b =% d / n", b); return 0;}