FreeCalypso > hg > fc-sim-tools
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 7:b25d4dfe5798 | 8:34bbb0585cab | 
|---|---|
| 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 } | 
