comparison loadtools/hexdecode.c @ 7:aa1f6fe16fef

loadtools building blocks started
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 30 Apr 2013 07:19:48 +0000
parents
children
comparison
equal deleted inserted replaced
6:5eaafa83be60 7:aa1f6fe16fef
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 }