Home »
C++ programming language
C++ 'bitor' Keyword with Examples
C++ | 'bitor' keyword: Here, we are going to learn about the 'bitor' keyword which is an alternative to Bitwise OR operator.
Submitted by IncludeHelp, on May 16, 2020
C++ 'bitor' Keyword
"bitor" is an inbuilt keyword that has been around since at least C++98. It is an alternative to | (Bitwise OR) operator and it mostly uses for bit manipulations.
The bitor keyword compares two bits and returns 1 if either of the bits is 1 and it returns 0 if both bits are 0 or 1.
Syntax
operand_1 bitor operand_2;
Here, operand_1 and operand_2 are the operands.
Sample Input and Output
Input:
bitset<4> value("1100");
bitset<4> mask ("1010");
value = value bitor mask;
Output:
value = 1110
C++ example to demonstrate the use of "bitor" keyword
// C++ example to demonstrate the use of
// 'bitor' keyword
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
//bitsets
bitset<4> value("1011");
bitset<4> mask1("1100");
bitset<4> mask2("0100");
// before operation
cout << "value: " << value << endl;
cout << "mask1: " << mask1 << endl;
cout << "mask2: " << mask2 << endl;
value = value bitor mask1;
cout << "After operation (1)...\n";
cout << "value: " << value << endl;
value = value bitor mask2;
cout << "After operation (2)...\n";
cout << "value: " << value << endl;
return 0;
}
Output
value: 1011
mask1: 1100
mask2: 0100
After operation (1)...
value: 1111
After operation (2)...
value: 1111