Created
May 29, 2014 13:37
-
-
Save hideo55/d0fd1a113c5e306790d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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