Skip to content

Instantly share code, notes, and snippets.

@a2800276
Last active November 8, 2023 14:58
Show Gist options
  • Save a2800276/4e3eb5edc2af9071ee9aab67d97216cc to your computer and use it in GitHub Desktop.
Save a2800276/4e3eb5edc2af9071ee9aab67d97216cc to your computer and use it in GitHub Desktop.
// simple helper to dump bytes in hex format
static void dump_bytes(uint8_t *bytes, size_t len) {
char buf[16 * 3 + 1];
buf[16 * 3] = '\0';
size_t i = 0;
for (i = 0; i < len; i++) {
if (i % 16 == 0) {
if (i > 0) {
printf("\n%s", buf);
}
printf("\n");
}
printf("%02x ", bytes[i]);
buf[(i % 16) * 3] = ' ';
buf[(i % 16) * 3 +1] = isprint(bytes[i]) ? bytes[i] : '.';
buf[(i % 16) * 3 +2] = ' ';
}
printf("\n%.*s (%d)", i%16 * 3, buf, i);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment