FreeCalypso > hg > freecalypso-reveng
comparison frbl/test/hexdecode.c @ 323:cefa700d1b8f
frbl: beginning of frbl2test
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 05 Mar 2020 22:05:01 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 322:6e442ed0f64d | 323:cefa700d1b8f |
|---|---|
| 1 /* | |
| 2 * This module contains the decode_hex_byte() function, | |
| 3 * which is used by the SREC file reader and will likely be used | |
| 4 * by other code as well, such as the dump-to-file function | |
| 5 * of loadtool. | |
| 6 */ | |
| 7 | |
| 8 #include <ctype.h> | |
| 9 | |
| 10 decode_hex_byte(s) | |
| 11 char *s; | |
| 12 { | |
| 13 register int u, l; | |
| 14 | |
| 15 if (!isxdigit(s[0]) || !isxdigit(s[1])) | |
| 16 return(-1); | |
| 17 if (isdigit(s[0])) | |
| 18 u = s[0] - '0'; | |
| 19 else if (isupper(s[0])) | |
| 20 u = s[0] - 'A' + 10; | |
| 21 else | |
| 22 u = s[0] - 'a' + 10; | |
| 23 if (isdigit(s[1])) | |
| 24 l = s[1] - '0'; | |
| 25 else if (isupper(s[1])) | |
| 26 l = s[1] - 'A' + 10; | |
| 27 else | |
| 28 l = s[1] - 'a' + 10; | |
| 29 return((u << 4) | l); | |
| 30 } |
