Skip to content

Instantly share code, notes, and snippets.

@ajarmst
Created January 31, 2020 17:09
Show Gist options
  • Save ajarmst/514a6b0995b86434d91f646e3560643e to your computer and use it in GitHub Desktop.
Save ajarmst/514a6b0995b86434d91f646e3560643e to your computer and use it in GitHub Desktop.
C Function to Print a Number in Binary to Console
//From another instructor. Provided for
//ICA 4, Lab 1
void printInBinary(unsigned char n) {
unsigned char mask = 0x80;
for (int i = 0; i < 8; i++) {
printf("%c ", (n & mask) ? '1' : '0');
mask = mask >> 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment