Skip to content

Instantly share code, notes, and snippets.

@ae-s
Last active February 11, 2023 01:55
Show Gist options
  • Save ae-s/11409252 to your computer and use it in GitHub Desktop.
Save ae-s/11409252 to your computer and use it in GitHub Desktop.
Hexdump suitable for debugging
#include <ctype.h>
#include <stdio.h>
void hexdump(void *ptr, int buflen) {
unsigned char *buf = (unsigned char*)ptr;
int i, j;
for (i=0; i<buflen; i+=16) {
printf("%06x: ", i);
for (j=0; j<16; j++)
if (i+j < buflen)
printf("%02x ", buf[i+j]);
else
printf(" ");
printf(" ");
for (j=0; j<16; j++)
if (i+j < buflen)
printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment