Skip to content

Instantly share code, notes, and snippets.

@wukaihua119
Created August 29, 2020 12:20
Show Gist options
  • Save wukaihua119/cb4c7a0872cc3d7704fe58604f2a6059 to your computer and use it in GitHub Desktop.
Save wukaihua119/cb4c7a0872cc3d7704fe58604f2a6059 to your computer and use it in GitHub Desktop.
// using mask to convert the integer to binary.
void printBin( int num ){
int mask = 1 << 7; // 10000000
for( int i = 0; i < 8; ++i ){
printf( "%d", ((( num & mask ) == 0 )? 0:1) );
mask >>= 1;
}
printf( "\n" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment