| - bitwise OR

suggest change
#include <iostream>
#include <string>

int main(int argc, char **argv) {
    int a = 5;     // 0101b  (0x05)
    int b = 12;    // 1100b  (0x0C)
    int c = a | b; // 1101b  (0x0D)
    
    std::cout << "a = " << a << ", b = " << b << ", c = " << c << std::endl;
}
a = 5, b = 12, c = 13

Why

A bit wise OR operates on the bit level and uses the following Boolean truth table:

true OR true = true
true OR false = true
false OR false = false

When the binary value for a (0101) and the binary value for b (1100) are OR’ed together we get the binary value of 1101:

int a = 0 1 0 1
int b = 1 1 0 0 |
        ---------
int c = 1 1 0 1

The bit wise OR does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator |=:

#include <iostream>
#include <string>

int main(int argc, char **argv) {
    int a = 5;  // 0101b  (0x05)
    a |= 12;    // a = 0101b | 1101b == 13

    std::cout << "a = " << a << std::endl;
}
a = 13

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Bit operators:
* | - bitwise OR

Table Of Contents
5 Bit operators
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype