Bitwise AND, OR, XOR Operations
C++
Medium
3 views
Problem Description
Perform bitwise operations on numbers.
Real Life: Used in low-level programming, flags, permissions.
Step-by-Step Logic:
1. AND (&): both bits must be 1
2. OR (|): at least one bit must be 1
3. XOR (^): bits must be different
4. Operations work on binary representation
Official Solution
void operator_q6_bitwise() {
int a = 12; // Binary: 1100
int b = 10; // Binary: 1010
cout << "a = " << a << " (binary: 1100)" << endl;
cout << "b = " << b << " (binary: 1010)" << endl;
cout << "a & b (AND): " << (a & b) << endl; // 1000 = 8
cout << "a | b (OR): " << (a | b) << endl; // 1110 = 14
cout << "a ^ b (XOR): " << (a ^ b) << endl; // 0110 = 6
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!