/// G. Hagopian -- bitwise sandbox

#include "std_lib_facilities.h"



// bitset operators
#include <iostream>       // cout
#include <string>         // std::string
#include <bitset>         // std::bitset

int main ()
{
  bitset<4> foo=9;  /// 9 = 1001_2
  bitset<4> bar (string("0011"));

  cout << foo << " ^ " << bar << " = " << (foo^bar) << '\n';       // 1010 (XOR,assign)
  foo^=bar;
  cout << foo << " & " << bar << " = " << (foo&=bar) << '\n';       // 0010 (AND,assign)
  cout << foo << " | " << bar << " = " << (foo|=bar) << '\n';       // 0011 (OR,assign)

  cout << foo << " <<2 " << bar << " = " << (foo<<=2) << '\n';        // 1100 (SHL,assign)
  cout << foo << " >>1 " << bar << " = " << (foo>>=1) << '\n';        // 0110 (SHR,assign)

  cout << " ~ " << bar << " = " << (~bar) << '\n';           // 1100 (NOT)
  cout << " <<1 " << bar << " = " << (bar<<1) << '\n';         // 0110 (SHL)
  cout << " >>1 " << bar << " = " << (bar>>1) << '\n';         // 0001 (SHR)

  cout << foo << " == " << bar << " = " << (foo==bar) << '\n';       // false (0110==0011)
  cout << foo << " != " << bar << " = " << (foo!=bar) << '\n';       // true  (0110!=0011)

  cout << foo << " & " << bar << " = " << (foo&bar) << '\n';        // 0010
  cout << foo << " | " << bar << " = " << (foo|bar) << '\n';        // 0111
  cout << foo << " ^ " << bar << " = " << (foo^bar) << '\n';        // 0101

  return 0;
}
