comparison libcoding/hexdigits.c @ 7:cd2d82ec5144

libcoding/hexdigits.c: import from fc-sim-tools/libutil
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 06:32:37 +0000
parents
children
comparison
equal deleted inserted replaced
6:b831ee7d512c 7:cd2d82ec5144
1 /*
2 * This module contains elementary functions for working with hex digits.
3 */
4
5 decode_hex_digit(c)
6 {
7 if (c >= '0' && c <= '9')
8 return(c - '0');
9 if (c >= 'A' && c <= 'F')
10 return(c - 'A' + 10);
11 if (c >= 'a' && c <= 'f')
12 return(c - 'a' + 10);
13 return(-1);
14 }
15
16 encode_hex_digit(d)
17 unsigned d;
18 {
19 if (d <= 9)
20 return(d + '0');
21 else
22 return(d - 10 + 'A');
23 }