Created
April 28, 2015 14:55
-
-
Save br0xen/eb80bec9277a8b055111 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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