comparison loadtools/hexdecode.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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 }