1 /* hex_dump.h -- simple hex dump routine
2 *
3 * Copyright (C) 2002 convergence GmbH
4 * Johannes Stezenbach <js@convergence.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "hex_dump.h"
25
26
hex_dump(uint8_t data[],int bytes)27 void hex_dump(uint8_t data[], int bytes)
28 {
29 int i, j;
30 uint8_t c;
31
32 for (i = 0; i < bytes; i++) {
33 if (!(i % 8) && i)
34 printf(" ");
35 if (!(i % 16) && i) {
36 printf(" ");
37 for (j = 0; j < 16; j++) {
38 c = data[i+j-16];
39 if ((c < 0x20) || (c >= 0x7f))
40 c = '.';
41 printf("%c", c);
42 }
43 printf("\n");
44 }
45 printf("%.2x ", data[i]);
46 }
47 j = (bytes % 16);
48 j = (j != 0 ? j : 16);
49 for (i = j; i < 16; i++) {
50 if (!(i % 8) && i)
51 printf(" ");
52 printf(" ");
53 }
54 printf(" ");
55 for (i = bytes - j; i < bytes; i++) {
56 c = data[i];
57 if ((c < 0x20) || (c >= 0x7f))
58 c = '.';
59 printf("%c", c);
60 }
61 printf("\n");
62 }
63