home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / libcs / atoh.c < prev    next >
C/C++ Source or Header  |  1990-12-11  |  2KB  |  69 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*  atoh  --  convert ascii to hexidecimal
  29.  *
  30.  *  Usage:  i = atoh (string);
  31.  *    unsigned int i;
  32.  *    char *string;
  33.  *
  34.  *  Atoo converts the value contained in "string" into an
  35.  *  unsigned integer, assuming that the value represents
  36.  *  a hexidecimal number.
  37.  *
  38.  *  HISTORY
  39.  * $Log:    atoh.c,v $
  40.  * Revision 1.2  90/12/11  17:50:07  mja
  41.  *     Add copyright/disclaimer for distribution.
  42.  * 
  43.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  44.  *    Created for VAX.
  45.  *
  46.  */
  47.  
  48. unsigned int atoh(ap)
  49. char *ap;
  50. {
  51.     register char *p;
  52.     register unsigned int n;
  53.     register int digit,lcase;
  54.  
  55.     p = ap;
  56.     n = 0;
  57.     while(*p == ' ' || *p == '    ')
  58.         p++;
  59.     while ((digit = (*p >= '0' && *p <= '9')) ||
  60.         (lcase = (*p >= 'a' && *p <= 'f')) ||
  61.         (*p >= 'A' && *p <= 'F')) {
  62.         n *= 16;
  63.         if (digit)    n += *p++ - '0';
  64.         else if (lcase)    n += 10 + (*p++ - 'a');
  65.         else        n += 10 + (*p++ - 'A');
  66.     }
  67.     return(n);
  68. }
  69.