Skip to content

Instantly share code, notes, and snippets.

@bjoern-r
Created October 13, 2014 10:28
Show Gist options
  • Save bjoern-r/b16b96f25c0e94f29bb1 to your computer and use it in GitHub Desktop.
Save bjoern-r/b16b96f25c0e94f29bb1 to your computer and use it in GitHub Desktop.
simple hexdump function borrowed from (boundarydevices/imx_usb_loader)
#include <stdio.h>
void hexdump_bytes(unsigned char *src, unsigned cnt, unsigned addr)
{
unsigned char *p = src;
int i;
while (cnt >= 16) {
printf("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", addr,
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
p += 16;
cnt -= 16;
addr += 16;
}
if (cnt) {
printf("%08x:", addr);
i = 0;
while (cnt) {
printf(" %02x", p[0]);
p++;
cnt--;
i++;
if (cnt) if (i == 4) {
i = 0;
printf(" ");
}
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment