Skip to content

Instantly share code, notes, and snippets.

@dalleng
Last active August 29, 2015 14:19
Show Gist options
  • Save dalleng/5af1b9768bd3416d49cc to your computer and use it in GitHub Desktop.
Save dalleng/5af1b9768bd3416d49cc to your computer and use it in GitHub Desktop.
Print 32 bit int as 4 binary octets
void printbint(unsigned int u32int) {
unsigned int mask = 1 << 31;
for (int i = 0; i < 32; i++) {
printf("%d", u32int & (mask >> i) ? 1 : 0);
if ((i + 1) % 8 == 0) {
printf(" ");
}
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment