把数据内容dump出来, 按照如下的内容格式:
00000000 00 00 00 00 82 47 00 00 9c 00 00 00 83 05 00 00 |.....G..........|
00000010 df a1 00 00 a0 00 00 00 79 0a 00 00 30 f8 00 00 |........y...0...|
00000020 a0 00 00 00 6f 0f 00 00 fa 4a 01 00 9e 00 00 00 |....o....J......|
00000030 67 14 00 00 6d a1 01 00 9b 00 00 00 1d 18 00 00 |g...m...........|
00000040 26 e0 01 00 56 01 00 00 0c 1d 00 00 be 32 02 00 |&...V........2..|
00000050 4a 01 00 00 dc 21 00 00 44 85 02 00 40 01 00 00 |J....!..D...@...|
00000060 f3 26 00 00 b7 db 02 00 39 01 00 00 e9 2b 00 00 |.&......9....+..|
00000070 3a 32 03 00 41 01 00 00 e2 30 00 00 d1 84 03 00 |:2..A....0......|
00000080 39 01 00 00 d5 35 00 00 58 d7 03 00 2a 01 00 00 |9....5..X...*...|
00000090 cc 3a 00 00 97 2d 04 00 40 01 00 00 c1 3f 00 00 |.:...-..@....?..|
000000A0 1e 80 04 00 40 01 00 00 b7 44 00 00 90 d6 04 00 |....@....D......|
000000B0 39 01 00 00 ac 49 00 00 7d 29 05 00 96 00 00 00 |9....I..})......|
000000C0 ad 4e 00 00 00 80 05 00 b2 00 00 00 a3 53 00 00 |.N...........S..|
000000D0 87 d2 05 00 de 00 00 00 99 58 00 00 e8 28 06 00 |.........X...(..|
000000E0 d8 00 00 00 16 5b 00 00 18 54 06 00 74 01 00 00 |.....[...T..t...|
000000F0 1e 61 00 00 39 ba 06 00 31 00 00 00 75 |.a..9...1...u|
#include <stdio.h>
#include <ctype.h>
static void _DumpLine(long addr, unsigned char* buf, int len)
{
int i, pos;
char line[80+1];
// Address field
pos = sprintf(line, "%08X ", addr);
// Hex content
for (i = 0; i < 16; ++i) {
if (i % (16/2) == 0) {
line[pos++] = ' '; // Insert a space
}
if (i < len) {
pos += sprintf(&line[pos], "%02x ", buf[i]);
} else {
pos += sprintf(&line[pos], " ");
}
}
pos += sprintf(&line[pos], " |");
// Printable content
for (i = 0; i < len; ++i) {
line[pos++] = isprint(buf[i]) ? buf[i] : '.';
}
sprintf(&line[pos], "|\n");
fprintf(stderr, "%s", line);
}
void DumpHex(unsigned char* buf, int len)
{
int i;
for (i = 0; i < (len/16); ++i) {
_DumpLine(16*i, &buf[16*i], 16);
}
// Dump remaining which len is not 16
if (len % 16 != 0) {
_DumpLine(16*i, &buf[16*i], len % 16);
}
}