Skip to content

Instantly share code, notes, and snippets.

@wukaihua119
Created August 29, 2020 12:20
Show Gist options
  • Select an option

  • Save wukaihua119/cb4c7a0872cc3d7704fe58604f2a6059 to your computer and use it in GitHub Desktop.

Select an option

Save wukaihua119/cb4c7a0872cc3d7704fe58604f2a6059 to your computer and use it in GitHub Desktop.

Revisions

  1. wukaihua119 created this gist Aug 29, 2020.
    9 changes: 9 additions & 0 deletions printBin.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    // 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" );
    }