FreeCalypso > hg > fc-pcsc-tools
annotate libutil/hexdigits.c @ 173:e70964adcbba
fc-simtool readef extended to fully dump all files
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 02 Mar 2021 03:33:41 +0000 |
parents | 3698c8192d2d |
children |
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 } |