Created
January 31, 2020 17:09
-
-
Save ajarmst/514a6b0995b86434d91f646e3560643e to your computer and use it in GitHub Desktop.
C Function to Print a Number in Binary to Console
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
| //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