comparison libutil/revnibbles.c @ 157:f064dbcc5f41

libutil split from libcommon
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 26 Feb 2021 20:19:58 +0000
parents libcommon/revnibbles.c@4360a7906f34
children 3698c8192d2d
comparison
equal deleted inserted replaced
156:5f1f3f6fd865 157:f064dbcc5f41
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 }