Semantics
Get introduced to semantics in this lesson.
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:
Press + to interact
import std.stdio;void print(uint number) {writefln(" %032b %08x %10s", number, number, number);}void main () {uint lhs = 0xaaaaaaaa;uint rhs = 0x55555555;print(lhs);print(rhs);writeln("| --------------------------------");print(lhs | rhs);}