C++ bitor Keyword
Example
The bitor keyword gives the same result as the | operator:
int x = 6;
int y = 3;
cout << (x bitor y) << "\n";
cout << (x | y);
Definition and Usage
The bitor keyword is another way to write the bitwise | operator. It compares the bits (the 1s and 0s that make up a number) of two numbers. A bit in the result is 1 if the bit is 1 in at least one of the numbers.
In the example, 6 is 110 in binary (base 2) and 3 is 011. Every bit is 1 in at least one of them, so the result is 111, which is 7.
Do not mix up bitor (|) with or (||). or works with true and false values, while bitor works on each bit.
Related Pages
Read more about operators in our C++ Operators Tutorial.