annotate libutil/hexdigits.c @ 206:f1cf569dbba3

fc-simtool erase-file & update-rec-fill: make fill byte always hex
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 05:21:24 +0000
parents 3698c8192d2d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
158
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains elementary functions for working with hex digits.
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 decode_hex_digit(c)
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 {
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 if (c >= '0' && c <= '9')
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 return(c - '0');
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 if (c >= 'A' && c <= 'F')
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 return(c - 'A' + 10);
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 if (c >= 'a' && c <= 'f')
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 return(c - 'a' + 10);
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 return(-1);
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 }
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 encode_hex_digit(d)
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned d;
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (d <= 9)
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(d + '0');
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 else
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(d - 10 + 'A');
3698c8192d2d libutil: hex digit functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }