C++ Program Bitwise Operators
Below is the implementation of the topic:
// C++ Program to demonstrate
// Bitwise Operator
#include <iostream>
using namespace std;
// Main function
int main()
{
int a = 5; // 101
int b = 3; // 011
// Bitwise AND
int bitwise_and = a & b;
// Bitwise OR
int bitwise_or = a | b;
// Bitwise XOR
int bitwise_xor = a ^ b;
// Bitwise NOT
int bitwise_not = ~a;
// Bitwise Left Shift
int left_shift = a << 2;
// Bitwise Right Shift
int right_shift = a >> 1;
// Printing the Results of
// Bitwise Operators
cout << "AND: " << bitwise_and << endl;
cout << "OR: " << bitwise_or << endl;
cout << "XOR: " << bitwise_xor << endl;
cout << "NOT a: " << bitwise_not << endl;
cout << "Left Shift: " << left_shift << endl;
cout << "Right Shift: " << right_shift << endl;
return 0;
}
Output:
AND: 1
OR: 7
XOR: 6
NOT a: -6
Left Shift: 20
Right Shift: 2
Bitwise Operators in C++
There are various Operators present in C++. Every Operator has a particular symbol as well as an Operation to perform. We have various categories of operators in C++.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
- Bitwise Operators
In this article, we will learn about the Bitwise Operators in C++.
Contact Us