#include using namespace std; /* The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1. The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different. */ int main() { int x1=1; // 001 int x2=2; // 010 int x3=3; // 011 int x4=4; // 100 int answer; cout << "x1 op x2" << endl; answer = x1 & x2; cout << " & " << answer << endl; answer = x1 ^ x2; cout << " ^ " << answer << endl; answer = x1 | x2; cout << " | " << answer << endl; cout << "x1 op x3" << endl; answer = x1 & x3; cout << " & " << answer << endl; answer = x1 ^ x3; cout << " ^ " << answer << endl; answer = x1 | x3; cout << " | " << answer << endl; cout << "x1 op x4" << endl; answer = x1 & x4; cout << " & " << answer << endl; answer = x1 ^ x4; cout << " ^ " << answer << endl; answer = x1 | x4; cout << " | " << answer << endl; return(0); }