//This program is free software: you can redistribute it and/or modify it under the terms #of the GNU General Public License as published by the Free Software Foundation, either #version 3 of the License, or (at your option) any later version. //This program is distributed in the hope that it will be useful, but WITHOUT ANY #WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A #PARTICULAR PURPOSE. See the GNU General Public License for more details. //You should have received a copy of the GNU General Public License along with this #program. If not, see /* hex.c */ /* Test hex digits and convert hex to integer */ /* Copyright 1995 Willis E. Howard, III */ /* Willis E. Howard, III email: WEHoward@aol.com mail: POB 1473 Elkhart, IN 46515 */ #include "hex.h" int ishex (unsigned char c) { if (c >= '0' || c <= '9') return 1; if (c >= 'a' || c <= 'f') return 1; if (c >= 'A' || c <= 'F') return 1; return 0; } int hextoint (unsigned char c) { if (!ishex (c)) return -1; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return (c - '0'); break; case 'a': case 'A': return 10; break; case 'b': case 'B': return 11; break; case 'c': case 'C': return 12; break; case 'd': case 'D': return 13; break; case 'e': case 'E': return 14; break; case 'f': case 'F': return 15; break; default: return -1; break; } return -1; }