Created
February 20, 2019 01:27
-
-
Save ti-nspire/3f9dd952432227e9155895d347ee57cf to your computer and use it in GitHub Desktop.
a function to print a one-byte value as a binary number.
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
#include <stdio.h> | |
// a function to print a one-byte value as a binary number. | |
void printByteAsBin(unsigned char oneByte){ | |
unsigned char binStr[8]; | |
unsigned char mask = 128; // 0b 1000 0000; | |
for(int i=0; i<8; i++){ | |
binStr[i] = (oneByte & mask) ? '1' : '0' ; | |
mask >>= 1; | |
} | |
printf("%s\r\n", binStr); | |
} | |
int main(){ | |
unsigned char oneByte = 0b11110000; | |
printByteAsBin(oneByte); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment