Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
bitset.cpp
Go to the documentation of this file.
1
29#include <bitset> // for bitset
30#include <iostream> // for cout, endl
31
32#include <examples.h>
33
34int main ()
35{
36 // Construct a bitset with 40 elements all initialized to 0.
37 std::bitset<40> b;
38
39 // Bitwise OR the bitset with 5.
40 b |= 5;
41
42 // Write bitset to the standard output.
43 std::cout << " 4....:....3....:....2....:....1....:....0\n"
44 << "b = 5: " << b << '\n';
45
46 // Invert the bitset.
47 b = ~b;
48
49 std::cout << "b = ~b: " << b << '\n'
50 << "b <<= " << b.count () << ": ";
51
52 // Shift the bitset left by the number of bits set.
53 b <<= b.count ();
54
55 // Convert it to a string and write it out again.
56 std::cout << b.to_string () << '\n';
57
58 // Return 0 on success.
59 return !(1 == b.count () && 1UL == (b >> (b.size () - 1)).to_ulong ());
60}
#define b
Definition 17.names.cpp:110
int main()
Definition bitset.cpp:34