home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff218.lzh / EdLib / toint.c < prev   
Text File  |  1989-06-04  |  671b  |  25 lines

  1. /*
  2.  * edlib v1.1 Copyright 1989 Edwin Hoogerbeets
  3.  * This code is freely redistributable as long as no charge other than
  4.  * reasonable copying fees are levied for it.
  5.  */
  6.  
  7. /*
  8.     toint is also not included in Manx. converts an ascii character
  9.     into its corresponding hexadecimal value. Can be used for
  10.     binary and decimal digits since these are subsets of the
  11.     hexadecimal character set.
  12. */
  13. int toint(c)
  14. register char c;
  15. {
  16.     if ( c >= '0' && c <= '9') {
  17.         return( c - '0' );
  18.     } else if ( c >= 'a' && c <= 'f' ) {
  19.         return( c - 'a' + 10 );
  20.     } else if ( c >= 'A' && c <= 'F' ) {
  21.         return( c - 'A' + 10 );
  22.     } else
  23.         return(-1);
  24. }
  25.