Merely understanding how these operators work at bit-level may not be sufficient to see how they are useful in programs. The following sections describe common ways that these operators are used.

| is a union set

The | operator produces the union of the 1 bits in the two expressions.

As an extreme example, let’s consider two values that both have alternating bits set to 1. The union of these values would produce a result where all of the bits are 1:

Get hands-on with 1400+ tech skills courses.