Advertisement
Guest User

Untitled

a guest
Dec 24th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. int htoi (char s[]) {
  2.  
  3.     int i,j,n;
  4.  
  5.     i = j = n = 0;
  6.  
  7.     char hex[] = "0123456789abcdef"; /*the array of possible hexadecimal digits*/
  8.  
  9.     if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) /*skip over the optional 0x or 0X*/
  10.  
  11.         i = 2;
  12.  
  13.     for (   ;s[i] != '\0'; i++) {
  14.  
  15.         for (j = 0; j <= 16; j++) {
  16.  
  17.             if ((s[i] == hex[j]) || (s[i] == toupper(hex[j])))
  18.  
  19.                 n = 16*n + j;
  20.  
  21.  
  22.                        }
  23.                     }
  24.  
  25.     return n;
  26.  
  27.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement