Skip to content

Instantly share code, notes, and snippets.

@kalloc
Last active September 30, 2015 18:48
Show Gist options
  • Save kalloc/1845640 to your computer and use it in GitHub Desktop.
Save kalloc/1845640 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
char raw[] = "\x0d\x0a\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff";
void hexdump(char *ptr, int len, int width) {
int count = 1;
printf("--------------------\n");
for(;len>0;len--,ptr++,count++) {
printf("%02X", (unsigned char)ptr[0]);
if (count==width) {
count = 0;
printf("\n");
} else {
printf(" ");
}
}
printf("\n");
printf("--------------------\n");
}
int main() {
hexdump(raw, sizeof(raw), 8);
}
@kalloc
Copy link
Author

kalloc commented Feb 16, 2012

--------------------
0D 0A 00 11 22 33 44 55
66 77 88 99 AA BB CC DD
EE FF 00 
--------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment