x <<= y (x = x << y)
x >>= y (x = x >> y)
x >>>= y (x = x >>> y)
x &= y (x = x & y)
x ^= y (x = x ^ y)
x |= y (x = x | y)
What do these different operators do?
The | (bitwise inclusive OR) operator compares the values (in binary format) of each operand and yields a value whose bit pattern shows which bits in either of the operands has the value 1 . If both of the bits are 0 , the result of that bit is 0 ; otherwise, the result is 1 .
Bitwise operators are usually applied to define flag values in operating systems and driver software. For instance, in a file property, the read-only mode is conceptually expressed as a flag bit in the operating system, and the bitwise operator is used to toggle between the true and the false value.
<<, >>
Bit shift left and right, respectively. If you imagine the left operand as a binary sequence of bits, you are shifting those to the left or right by the number of bits indicated by the right operand.
&, ^, |
These are bitwise and, xor, and or, respectively. You can think of &
and |
as the counterparts to &&
and ||
, except that they will treat their operands as bit vectors, and perform the logical operations on each of the bits. There is no ^^
operator, but this operation is "xor" or "exclusive or". You can think of "a xor b" as "a or b, but not both".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With