FreeCalypso > hg > fc-sim-tools
comparison libutil/revnibbles.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 implements some reversed-nibbles parsing functions. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 | |
| 7 decode_reversed_nibbles(bytes, nbytes, dest) | |
| 8 u_char *bytes; | |
| 9 unsigned nbytes; | |
| 10 char *dest; | |
| 11 { | |
| 12 u_char *sp; | |
| 13 char *dp; | |
| 14 unsigned n, c; | |
| 15 | |
| 16 sp = bytes; | |
| 17 dp = dest; | |
| 18 for (n = 0; n < nbytes; n++) { | |
| 19 c = *sp & 0xF; | |
| 20 *dp++ = encode_hex_digit(c); | |
| 21 c = *sp >> 4; | |
| 22 *dp++ = encode_hex_digit(c); | |
| 23 sp++; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 pack_reversed_nibbles(nibbles, bytes, nbytes) | |
| 28 u_char *nibbles, *bytes; | |
| 29 unsigned nbytes; | |
| 30 { | |
| 31 u_char *sp, *dp; | |
| 32 unsigned n; | |
| 33 | |
| 34 sp = nibbles; | |
| 35 dp = bytes; | |
| 36 for (n = 0; n < nbytes; n++) { | |
| 37 *dp++ = sp[0] | (sp[1] << 4); | |
| 38 sp += 2; | |
| 39 } | |
| 40 } |
