Created
November 16, 2014 00:30
-
-
Save StuffAndyMakes/a91bf33632c61da278f6 to your computer and use it in GitHub Desktop.
Quick Easy Binary Value Print Function
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
| String printBigBinary( uint32_t n, int spacing ) { | |
| int bitPosition = sizeof(n) * 8 - 1; | |
| String bits = ""; | |
| while (bitPosition >= 0) { | |
| bits += (n & (1UL<<bitPosition)) == (1UL<<bitPosition) ? "1" : "0"; | |
| if (bitPosition % spacing == 0) { | |
| bits += " "; | |
| } | |
| bitPosition--; | |
| } | |
| return bits; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment