Skip to content

Instantly share code, notes, and snippets.

@br0xen
Created April 28, 2015 14:55
Show Gist options
  • Save br0xen/eb80bec9277a8b055111 to your computer and use it in GitHub Desktop.
Save br0xen/eb80bec9277a8b055111 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <bitset>
using namespace std;
int main() {
cout << "* Left Bitshift: \n";
int a = 3; bitset<8> x(a);
cout << "a = \t\t" << a << "\t" << x << "\n";
cout << "a <<= 2 is \t" << (a <<= 2) << "\t" << (x <<= 2) << "\n\n";
cout << "* Right Bitshift: \n";
a = 3; x = 3;
cout << "a = \t\t" << a << "\t" << x << "\n";
cout << "a >>= 1 is \t" << (a >>= 1) << "\t" << (x >>=1) << "\n\n";
cout << "* Bitwise AND: \n";
a = 3; x = 3;
int b = 2; bitset<8> y(b);
cout << "a = \t\t" << a << "\t" << x << "\n";
cout << "b = \t\t" << b << "\t" << y << "\n";
cout << "a &= b is \t" << (a &= b) << "\t" << (x &= y) << "\n\n";
cout << "* Bitwise OR: \n";
a = 11; x = 11;
b = 4; y = 4;
cout << "a = \t\t" << a << "\t" << x << "\n";
cout << "b = \t\t" << b << "\t" << y << "\n";
cout << "a |= b is \t" << (a |= b) << "\t" << (x |= y) << "\n\n";
cout << "* Bitwise XOR: \n";
a = 11; x = 11;
b = 2; y = 2;
cout << "a = \t\t" << a << "\t" << x << "\n";
cout << "b = \t\t" << b << "\t" << y << "\n";
cout << "a ^= b is \t" << (a ^= b) << "\t" << (x ^= y) << "\n\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment