FreeCalypso > hg > fc-sim-tools
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/revnibbles.c Sun Mar 14 05:42:37 2021 +0000 @@ -0,0 +1,40 @@ +/* + * This module implements some reversed-nibbles parsing functions. + */ + +#include <sys/types.h> + +decode_reversed_nibbles(bytes, nbytes, dest) + u_char *bytes; + unsigned nbytes; + char *dest; +{ + u_char *sp; + char *dp; + unsigned n, c; + + sp = bytes; + dp = dest; + for (n = 0; n < nbytes; n++) { + c = *sp & 0xF; + *dp++ = encode_hex_digit(c); + c = *sp >> 4; + *dp++ = encode_hex_digit(c); + sp++; + } +} + +pack_reversed_nibbles(nibbles, bytes, nbytes) + u_char *nibbles, *bytes; + unsigned nbytes; +{ + u_char *sp, *dp; + unsigned n; + + sp = nibbles; + dp = bytes; + for (n = 0; n < nbytes; n++) { + *dp++ = sp[0] | (sp[1] << 4); + sp += 2; + } +}