Skip to content

Instantly share code, notes, and snippets.

@adh
Created May 25, 2012 15:01
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 adh/2788618 to your computer and use it in GitHub Desktop.
Save adh/2788618 to your computer and use it in GitHub Desktop.
static void hexdump(unsigned char* buf, size_t len){
int i;
for(;;){
fprintf(stderr, " ");
for (i = 0; i < 16; i++){
if (len <= i){
fprintf(stderr, " ");
} else{
fprintf(stderr, "%02hhx ", buf[i]);
}
}
for (i = 0; i < 16; i++){
if (len <= i){
fprintf(stderr, " ");
} else if (buf[i] > ' ' && buf[i] < 127){
fprintf(stderr, "%c", buf[i]);
} else {
fprintf(stderr, ".");
}
}
fprintf(stderr, "\n");
if (len < 16){
break;
}
len-=16;
buf+=16;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment