Table Of Contents
Previous Section Next Section

Program 42: A Bit More Trouble

We fixed Program 41 by changing line 19. So now the program works, right? Of course not. What would a working program be doing in this book?

  1 /************************************************
  2  * bit test -- Test the routine to print out    *
  3  *      the bits in a flag.                     *
  4  ************************************************/
  5 #include <iostream>
  6 /************************************************
  7  * bit_out -- print a graphical                 *
  8  *      representation of each bit in a         *
  9  *      16 bit word.                            *
 10  *                                              *
 11  * For example:                                 *
 12  *      0×55AF will print -X-X-X-XX-X-XXXX      *
 13  ************************************************/
 14 void bit_out(
 15     const short int value       // Value to print
 16 )
 17 {
 18     // The bit we are printing now
 19     short int bit = (1<<15);
 20
 21     int count;                  // Loop counter
 22
 23     for (count = 0; count < 16; ++count)
 24     {
 25         if ((bit & value) != 0)
 26             std::cout << "X";
 27         else
 28             std::cout << '-';
 29         bit >>= 1;
 30     }
 31     std::cout << std::endl;
 32 }
 33 int main()
 34 {
 35     bit_out(0×55AF);
 36     return (0);
 37 }

(Next Hint 180. Answer 19.)

Table Of Contents
Previous Section Next Section