annotate libcoding/hexdigits.c @ 28:6e925aa54727

libcoding: more sensible naming of GSM time encoding and decoding modules
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Jun 2024 02:32:11 +0000
parents cd2d82ec5144
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains elementary functions for working with hex digits.
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 decode_hex_digit(c)
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 {
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 if (c >= '0' && c <= '9')
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 return(c - '0');
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 if (c >= 'A' && c <= 'F')
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 return(c - 'A' + 10);
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 if (c >= 'a' && c <= 'f')
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 return(c - 'a' + 10);
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 return(-1);
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 }
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 encode_hex_digit(d)
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned d;
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (d <= 9)
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(d + '0');
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 else
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(d - 10 + 'A');
cd2d82ec5144 libcoding/hexdigits.c: import from fc-sim-tools/libutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }