Skip to content

Instantly share code, notes, and snippets.

@henryscala
Created February 1, 2016 02:16
Show Gist options
  • Save henryscala/61a6fa2dd7f8de23b43d to your computer and use it in GitHub Desktop.
Save henryscala/61a6fa2dd7f8de23b43d to your computer and use it in GitHub Desktop.
a c function to dump the buffer in hex
#include <stdio.h>
char hexstr[]="0123456789ABCDEF";
void hexdump(char* buf, int len) {
int i;
for(i=0;i<len;++i) {
int hi=(buf[i] >> 4) & 0x0f;
int lo=(buf[i] & 0x0f);
printf("%c%c,",hexstr[hi],hexstr[lo]);
}
printf("\n");
}
int main()
{
char buf[100];
hexdump(buf,100);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment