Skip to content

Instantly share code, notes, and snippets.

@hideo55
Created May 29, 2014 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideo55/d0fd1a113c5e306790d8 to your computer and use it in GitHub Desktop.
Save hideo55/d0fd1a113c5e306790d8 to your computer and use it in GitHub Desktop.
#include <cstdio>
void hexDump(const void *buf, int size)
{
int i,j;
unsigned char *p = (unsigned char *)buf, tmp[20];
printf("+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F| -- ASCII --\r\n");
printf("--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+----------------\r\n");
for (i=0; p-(unsigned char *)buf<size; i++) {
for (j=0; j<16; j++) {
tmp[j] = (unsigned char)((*p<0x20||*p>=0x7f)? '.': *p);
printf("%02X ", (int)*p);
if (++p-(unsigned char *)buf>=size) {
tmp[++j] = '\0';
for (;j<16;j++) {
printf(" ");
}
break;
}
}
tmp[16] = '\0';
printf("%s\r\n", tmp);
if (p-(unsigned char *)buf>=size) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment