...  number2{199};
32     cout << "\nThe result of combining the following\n";
33     displayBits(number1);
34     displayBits(number2);
35     cout << "using the bitwise exclusive OR operator ^ is\n";
36     displayBits(number1 ^ number2);
37
38     // demonstrate bitwise complement
39     number1 = 21845;
40     cout << "\nThe one's complement of\n";
41     displayBits(number1);
42     cout << "is" << endl;
43     displayBits(~number1);
44  }
45
46  // display bits of an unsigned integer value
47  void displayBits(unsigned value) {
48     const unsigned SHIFT{8 * sizeof(unsigned) - 1};
49     const unsigned MASK{static_cast<const unsigned>(1 << SHIFT)};
50
51     cout << setw(10) << value << " = ";
52
53     // display bits
54     for (unsigned i{1}; i <= SHIFT + 1; ++i) {
55        cout << (value & MASK ? '1' : '0'

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.