Skip to content

Commit

Permalink
Added hexdump.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Patel authored and Edward Patel committed Jan 5, 2010
1 parent 86efd26 commit 1400f37
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions C/hexdump/hexdump.c
@@ -0,0 +1,20 @@
#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");
}
}

0 comments on commit 1400f37

Please sign in to comment.