Skip to content

Instantly share code, notes, and snippets.

@StuffAndyMakes
Created November 16, 2014 00:30
Show Gist options
  • Select an option

  • Save StuffAndyMakes/a91bf33632c61da278f6 to your computer and use it in GitHub Desktop.

Select an option

Save StuffAndyMakes/a91bf33632c61da278f6 to your computer and use it in GitHub Desktop.
Quick Easy Binary Value Print Function
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