todigit.c 812 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*====================================================================*
  2. *
  3. * unsigned todigit (unsigned c);
  4. *
  5. * number.h
  6. *
  7. * return the unsigned integer equivalent of an ASCII digit or the
  8. * value UCHAR_MAX on error;
  9. *
  10. * Motley Tools by Charles Maier;
  11. * Copyright (c) 2001-2006 by Charles Maier Associates;
  12. * Licensed under the Internet Software Consortium License;
  13. *
  14. *--------------------------------------------------------------------*/
  15. #ifndef TODIGIT_SOURCE
  16. #define TODIGIT_SOURCE
  17. #include <limits.h>
  18. #include "../tools/number.h"
  19. unsigned todigit (unsigned c)
  20. {
  21. if ((c >= '0') && (c <= '9'))
  22. {
  23. return (c - '0');
  24. }
  25. if ((c >= 'A') && (c <= 'Z'))
  26. {
  27. return (c - 'A' + 10);
  28. }
  29. if ((c >= 'a') && (c <= 'z'))
  30. {
  31. return (c - 'a' + 10);
  32. }
  33. return (UCHAR_MAX);
  34. }
  35. #endif