O'Reilly logo

C++11 for Programmers, Second Edition by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Printing a Binary Representation of an Integral Value

When using the bitwise operators, it’s useful to illustrate their precise effects by printing values in their binary representation. The program of Fig. 20.6 prints an unsigned integer in its binary representation in groups of eight bits each.

 1   // Fig. 20.6: fig20_06.cpp 2   // Printing an unsigned integer in bits. 3   #include <iostream> 4   #include <iomanip> 5   using namespace std; 6  7   void displayBits( unsigned ); // prototype 8  9   int main()10   {11      unsigned inputValue = 0; // integral value to print in binary12 13      cout << "Enter an unsigned integer: ";14      cin >> inputValue;15      displayBits( inputValue );16   } // end main17

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required