#include <boost/dynamic_bitset.hpp>
#include <iostream>
using
namespace
std;
int
main(
int
argc,
char
* argv[])
{
int
n_bits = 8;
boost::dynamic_bitset<> B1(n_bits, 123);
boost::dynamic_bitset<> B2(n_bits, 206);
boost::dynamic_bitset<> temp(4, 3);
cout <<
"Binary representation of 123: "
<< B1 << endl;
cout <<
"Binary representation of 206: "
<< B2 << endl
<< endl;
cout <<
"4th bit of B1 consist: "
<< B1[3] << endl;
B1[3] = 0;
cout <<
"Assigning 0 to 4th bit of B1: "
<< B1 << endl
<< endl;
cout <<
"temp before assignment: "
<< temp << endl;
temp.operator=(B1);
cout <<
"temp after assignment with B1: "
<< temp << endl
<< endl;
cout <<
"B1 consist of: "
<< B1 << endl;
cout <<
"B2 consist of: "
<< B2 << endl;
temp.operator=(B1);
temp.operator&=(B2);
cout <<
"B1 AND B2 is : & "
<< temp << endl
<< endl;
cout <<
"B1 consist of: "
<< B1 << endl;
cout <<
"B2 consist of: "
<< B2 << endl;
temp.operator=(B1);
temp.operator|=(B2);
cout <<
"B1 OR B2 is : | "
<< temp << endl
<< endl;
cout <<
"B1 consist of: "
<< B1 << endl;
cout <<
"B2 consist of: "
<< B2 << endl;
temp.operator=(B1);
temp.operator^=(B2);
cout <<
"B1 XOR B2 is : ^ "
<< temp << endl
<< endl;
cout <<
"B1 consist of: "
<< B1 << endl;
cout <<
"B2 consist of: "
<< B2 << endl;
temp.operator=(B1);
temp.operator-=(B2);
cout <<
"Set differ is: "
<< temp << endl
<< endl;
cout <<
"dynamic_bitset B1 and B2 are "
<< (operator==(B1, B2) ?
"equal"
:
"not equal"
)
<< endl;
boost::dynamic_bitset<> B3(2, 0), B4(3, 0);
cout <<
"Content of B3: "
<< B3 << endl
<<
"Content of B4: "
<< B4 << endl
<<
"dynamic_bitset B3 and B4 are "
<< (operator==(B3, B4) ?
"equal"
:
"not equal"
)
<< endl;
B3.operator=(B4);
cout <<
"dynamic_bitset B3 and B4 are: "
<< (operator==(B3, B4) ?
"equal"
:
"not equal"
)
<< endl
<< endl;
cout <<
"dynamic_bitset B1 and B2 are "
;
cout << (operator!=(B1, B2) ?
"not equal"
:
"equal"
)
<< endl
<< endl;
cout <<
"B1 consist of: "
<< B1 << endl;
cout <<
"B2 consist of: "
<< B2 << endl;
if
(operator<(B1, B2))
cout <<
"B1 is lexicographically less than B2"
;
else
cout <<
"B2 is lexicographically greater than B2"
;
cout << endl
<< endl;
cout <<
"B1 consist of: "
<< B1 << endl;
boost::dynamic_bitset<> B5(8, 0);
cout <<
"B5 consist of: "
<< B5 << endl;
if
(operator>(B1, B5))
cout <<
"B1 is lexicographically greater than B5"
;
else
cout <<
"B1 is lexicographically less than B5"
;
cout << endl
<< endl;
cout <<
"B3 is lexicographically "
;
if
(operator<=(B3, B3))
cout <<
"less than or equal to B3"
<< endl
<< endl;
else
cout <<
"greater than B3"
<< endl
<< endl;
cout <<
"B5 consist of: "
<< B5 << endl;
cout <<
"B2 consist of: "
<< B2 << endl;
cout <<
"B5 is lexicographically "
;
if
(operator>=(B5, B2))
cout <<
"greater than or equal to B2"
;
else
cout <<
"less than B2"
;
cout << endl
<< endl;
cout <<
"Value of dynamic_bitset B4 : "
<< B4 << endl;
cout <<
"Creating flipped copy of B4: "
;
cout << B4.operator~() << endl
<< endl;
cout <<
"Value of dynamic_bitset B2: "
<< B2 << endl;
cout <<
"Copy of B2 left shift 3 times is : "
;
cout << B2.operator<<(3) << endl;
cout <<
"Copy of B2 right shift 1 time is : "
;
cout << B2.operator>>(1) << endl
<< endl;
cout <<
"Value of dynamic_bitset B2: "
<< B2 << endl;
cout <<
"B2 left shift 3 times is : "
;
cout << B2.operator<<=(2) << endl;
cout <<
"B2 right shift 1 time is : "
;
cout << B2.operator>>=(3);
return
0;
}