/** Helpful program to report the value in every byte of stdin, in binary. */ #include void printBits( unsigned char ch ) { // Start printing bits from the high-order one. for ( int i = 7; i >= 0; i-- ) printf( "%c", ch & ( 0x01 << i ) ? '1' : '0' ); } int main() { // Shouldn't need this on a Unix machine, but it might make a difference // on windows. freopen( NULL, "rb", stdin ); int idx = 0; int ch; // Read the contents of input. while ( ( ch = getchar() ) != EOF ) { // Print byte index, followed by its binary representation. printf( "%04x ", idx ); printBits( ch ); printf( "\n" ); idx++; } }