home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / misc / smc203.ark / XTOI.C < prev   
Encoding:
Text File  |  1983-07-28  |  512 b   |  21 lines

  1.  
  2. /*
  3. ** xtoi -- convert hex string to integer nbr
  4. **         returns field size, else ERR on error
  5. */
  6. xtoi(hexstr, nbr)  char *hexstr;  int *nbr;  {
  7.   int d,t; d=0;
  8.   *nbr=0;
  9.   while(1)
  10.     {
  11.     if((*hexstr>='0')&(*hexstr<='9')) t=48;
  12.     else if((*hexstr>='A')&(*hexstr<='F')) t=55;
  13.     else if((*hexstr>='a')&(*hexstr<='f')) t=87;
  14.     else break;
  15.     if(d<4) ++d; else return ERR;
  16.     *nbr = *nbr<<4;
  17.     *nbr = *nbr+(*hexstr++)-t;
  18.     }
  19.   return d;
  20.   }
  21.