From 6e40287e2f39a80fc72bd8d0fbc1a8334d688c2d Mon Sep 17 00:00:00 2001 From: etobi Date: Tue, 3 Sep 2013 09:48:38 +0200 Subject: Imported Upstream version 1.1.0 --- test/hex_dump.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/hex_dump.c (limited to 'test/hex_dump.c') diff --git a/test/hex_dump.c b/test/hex_dump.c new file mode 100644 index 0000000..c7c8ede --- /dev/null +++ b/test/hex_dump.c @@ -0,0 +1,63 @@ +/* hex_dump.h -- simple hex dump routine + * + * Copyright (C) 2002 convergence GmbH + * Johannes Stezenbach + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "hex_dump.h" + + +void hex_dump(uint8_t data[], int bytes) +{ + int i, j; + uint8_t c; + + for (i = 0; i < bytes; i++) { + if (!(i % 8) && i) + printf(" "); + if (!(i % 16) && i) { + printf(" "); + for (j = 0; j < 16; j++) { + c = data[i+j-16]; + if ((c < 0x20) || (c >= 0x7f)) + c = '.'; + printf("%c", c); + } + printf("\n"); + } + printf("%.2x ", data[i]); + } + j = (bytes % 16); + j = (j != 0 ? j : 16); + for (i = j; i < 16; i++) { + if (!(i % 8) && i) + printf(" "); + printf(" "); + } + printf(" "); + for (i = bytes - j; i < bytes; i++) { + c = data[i]; + if ((c < 0x20) || (c >= 0x7f)) + c = '.'; + printf("%c", c); + } + printf("\n"); +} + -- cgit v1.2.3