Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 905
rsavchenko Avatar asked Nov 20 '25 16:11

rsavchenko


1 Answers

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.

like image 136
joews Avatar answered Nov 23 '25 09:11

joews



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!