Created
May 6, 2012 02:39
-
-
Save igorsobreira/2607166 to your computer and use it in GitHub Desktop.
Hexdump, useful to debug C code. From ##c irc channel
This file contains 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
/* HEXDUMP */ | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
void hexdump(const void * memory, size_t bytes) { | |
const unsigned char * p, * q; | |
int i; | |
p = memory; | |
while (bytes) { | |
q = p; | |
printf("%p: ", (void *) p); | |
for (i = 0; i < 16 && bytes; ++i) { | |
printf("%02X ", *p); | |
++p; | |
--bytes; | |
} | |
bytes += i; | |
while (i < 16) { | |
printf("XX "); | |
++i; | |
} | |
printf("| "); | |
p = q; | |
for (i = 0; i < 16 && bytes; ++i) { | |
printf("%c", isprint(*p) && !isspace(*p) ? *p : ' '); | |
++p; | |
--bytes; | |
} | |
while (i < 16) { | |
printf(" "); | |
++i; | |
} | |
printf(" |\n"); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment