Skip to content

Instantly share code, notes, and snippets.

@buchgr
Created December 11, 2014 21:53
Show Gist options
  • Save buchgr/6ed2e12fae3bae7ffa81 to your computer and use it in GitHub Desktop.
Save buchgr/6ed2e12fae3bae7ffa81 to your computer and use it in GitHub Desktop.
// print each byte from [begin, end) in groups of four per line
void bindump(const uint8_t* begin, const uint8_t* end) {
printf("BIN[%p, %p)\n", begin, end);
char bytestr[9];
bytestr[8] = '\0';
for (uint8_t j = 1; begin != end; begin++, j++) {
uint8_t byte = *begin;
for (int i = 0; i < 8; i++)
bytestr[i] = '0' + ((byte >> (7-i)) & 1);
printf("%s%c", bytestr, j & 3 ? ' ' : '\n');
}
putchar('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment