FreeCalypso > hg > fc-sim-tools
annotate libutil/hexdigits.c @ 8:34bbb0585cab
libutil: import from previous fc-pcsc-tools version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 05:42:37 +0000 |
parents | |
children |
rev | line source |
---|---|
8
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains elementary functions for working with hex digits. |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 decode_hex_digit(c) |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 if (c >= '0' && c <= '9') |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 return(c - '0'); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 if (c >= 'A' && c <= 'F') |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 return(c - 'A' + 10); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 if (c >= 'a' && c <= 'f') |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 return(c - 'a' + 10); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 return(-1); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 } |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 encode_hex_digit(d) |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 unsigned d; |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (d <= 9) |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 return(d + '0'); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 else |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(d - 10 + 'A'); |
34bbb0585cab
libutil: import from previous fc-pcsc-tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |