Search code examples
bitmaplogicbit-manipulationoperator-precedence

Bitwise operators order of precedence


According to Wikipedia, the bitwise AND operator has higher precedence than the bitwise OR. However wolfram says they are equivalent. Are the following two expressions equivalent?

C &  A | B
C & (A | B)

My thoughts are that they are the same since I believe | and & have the same precedence, so we just evaluate left to right.


Solution

  • In theory any language or logic system could dictate the precedence of its operators. However, in all languages I am familiar with, bitwise (and logical, for that matter) AND has higher precedence than OR.

    Given that & and | are fundamental operators and, crucially, (a & b) | c = d does not imply a & (b | c) =d, it seems very unlikely that any real language would leave their relative precedence undefined.