Bit prediction

I got several times in C-like languages:

original | included & ~excluded   // BAD

Owing to priority, it analyzes as:

original | (included & ~excluded)   // '~excluded' has no effect

Does anyone know what was behind the initial design decision from three separate priority levels for bitwise operators? More importantly, do you agree with this decision and why?

+3
source share
2 answers

Operators have this priority, at least, the C .

I agree with the order because it is the same relative order as the relative order of arithmetic operators, which is most similar to ( +, *and negation).

& vs * | vs + :

A  B | A&B A*B | A|B A+B 
0  0 |  0   0  |  0   0
0  1 |  0   0  |  1   1
1  0 |  0   0  |  1   1
1  1 |  1   1  |  1   2

:

~A = -A - 1
+6

Source: https://habr.com/ru/post/1765189/


All Articles