Using bitset to show bit patterns

There is no manipulator to tell the cout object to print an integer as a bitmap, but you can simulate the behavior using a bitset object:

    // #include <bitset>     unsigned long long every_other = 0xAAAAAAAAAAAAAAAA;     unsigned long long each_other  = 0x5555555555555555;     bitset<64> bs_every(every_other);     bitset<64> bs_each(each_other);     cout << bs_every << endl;     cout << bs_each << endl;

The result is:

    1010101010101010101010101010101010101010101010101010101010101010        0101010101010101010101010101010101010101010101010101010101010101

Here the bitset class is parameterized, which means that you provide a parameter through the angle brackets (<>) and in this case, 64 is used, indicating that the bitset object ...

Get Beginning C++ Programming 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.