Last active
October 13, 2022 20:12
-
-
Save mtfurlan/a3a44246e6ea89809a87aac3d17c5bd2 to your computer and use it in GitHub Desktop.
c function to emulate xxd -g1
This file contains 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 <ctype.h> | |
// based on https://stackoverflow.com/q/54500648/2423187 | |
void hexDump(const uint8_t* data, int len) | |
{ | |
int i; | |
unsigned char bufferLine[17]; | |
for (i = 0; i < len; i++) { | |
if ((i % 16) == 0) { | |
if (i != 0) { | |
printf(" %s\n", bufferLine); | |
} | |
printf("%08x:", i); | |
} | |
printf(" %02x", data[i]); | |
bufferLine[i % 16] = isprint(data[i]) ? data[i] : '.'; | |
bufferLine[(i % 16) + 1] = '\0'; | |
} | |
while ((i % 16) != 0) { | |
printf(" "); | |
i++; | |
} | |
printf(" %s\n", bufferLine); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment