Created
January 1, 2017 04:28
-
-
Save hugolu/334f068409cbc8365ce5b476c23aa892 to your computer and use it in GitHub Desktop.
hexdump in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MIN(A,B) ((A) < (B) ? (A) : (B)) | |
void hexdump(void *buf, int size) { | |
unsigned char *ptr; | |
int i, j, len = 0; | |
for (i = 0; i < size; i += len) { | |
ptr = buf + i; | |
len = MIN(16, size - i); | |
printf("%04x | ", i); | |
for (j = 0; j < len; j++) { | |
printf("%02x ", ptr[j]); | |
} | |
printf("\n"); | |
} | |
} | |
int main() { | |
unsigned char buf[256]; | |
int i; | |
for (i = 0; i < 256; i++) buf[i] = (unsigned char)i; | |
hexdump (buf, 256); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment