FreeCalypso > hg > fc-pcsc-tools
comparison libcommon/revnibbles.c @ 7:4360a7906f34
reversed nibbles parsing functions factored out into libcommon
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 11 Feb 2021 23:56:13 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:2c72709e0891 | 7:4360a7906f34 |
---|---|
1 /* | |
2 * This module implements some reversed-nibbles parsing functions. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 | |
7 encode_hex_digit(d) | |
8 unsigned d; | |
9 { | |
10 if (d <= 9) | |
11 return(d + '0'); | |
12 else | |
13 return(d - 10 + 'A'); | |
14 } | |
15 | |
16 decode_reversed_nibbles(bytes, nbytes, dest) | |
17 u_char *bytes; | |
18 unsigned nbytes; | |
19 char *dest; | |
20 { | |
21 u_char *sp; | |
22 char *dp; | |
23 unsigned n, c; | |
24 | |
25 sp = bytes; | |
26 dp = dest; | |
27 for (n = 0; n < nbytes; n++) { | |
28 c = *sp & 0xF; | |
29 *dp++ = encode_hex_digit(c); | |
30 c = *sp >> 4; | |
31 *dp++ = encode_hex_digit(c); | |
32 sp++; | |
33 } | |
34 } |