Last active
August 29, 2015 14:19
-
-
Save dalleng/5af1b9768bd3416d49cc to your computer and use it in GitHub Desktop.
Print 32 bit int as 4 binary octets
This file contains 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
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