Skip to content

Instantly share code, notes, and snippets.

@theoremoon
Created September 26, 2014 21:09
Show Gist options
  • Save theoremoon/8c2d29b1d3c7bab0fbb7 to your computer and use it in GitHub Desktop.
Save theoremoon/8c2d29b1d3c7bab0fbb7 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(){
int a = 0b1111; // 15
int b = 0xF; // 15
cout << a << endl <<
b << endl;
if (a == b){
cout << "Same" << endl;
} else {
cout << "Different" << endl;
}
int c = 0b0010;
cout << (a + c) << endl <<
(a & c) << endl <<
(a | c) << endl <<
(a ^ c) << endl <<
( ~a ) << endl << endl;
int flag = 0b0011;
enum class flags : int {
a = 1,
b,
c,
d,
};
if (flag & static_cast<int>(flags::a)){
cout << "a is true" << endl;
} if (flag & static_cast<int>(flags::b)){
cout << "b is true" << endl;
} if (flag & static_cast<int>(flags::c)){
cout << "c is true" << endl;
} if (flag & static_cast<int>(flags::d)){
cout << "d is true" << endl;
}
cout << (a << 1) << endl;
return 0;
}
/* -- result --
15
15
Same
17
2
15
13
-16
a is true
b is true
c is true
30
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment