Created
December 11, 2014 21:53
-
-
Save buchgr/6ed2e12fae3bae7ffa81 to your computer and use it in GitHub Desktop.
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
// 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