comparison target-utils/libload/hexstrings.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 * The decode_hex_digits() function contained in this module
3 * will be used by the XRAM and flash loading commands
4 * which take SREC-like long hex string arguments.
5 */
6
7 #include <ctype.h>
8 #include "types.h"
9
10 decode_hex_digits(str, ndigits, valp)
11 char *str;
12 int ndigits;
13 u32 *valp;
14 {
15 u32 accum;
16 int i, c;
17
18 accum = 0;
19 for (i = 0; i < ndigits; i++) {
20 c = *str++;
21 if (!isxdigit(c))
22 return(-1);
23 accum <<= 4;
24 if (isdigit(c))
25 accum += c - '0';
26 else if (islower(c))
27 accum += c - 'a' + 10;
28 else
29 accum += c - 'A' + 10;
30 }
31 *valp = accum;
32 return(0);
33 }