comparison libutil/hexdigits.c @ 158:3698c8192d2d

libutil: hex digit functions factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 26 Feb 2021 20:41:31 +0000
parents
children
comparison
equal deleted inserted replaced
157:f064dbcc5f41 158:3698c8192d2d
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 }