Bitwise Operator Precedence

  • Thread starter Lawrence D'Oliveiro
  • Start date
L

Lawrence D'Oliveiro

One of the awkwardnesses Java carries over from C/C++ is the precedence of
bitwise operators is lower than that of comparisons. Thus you need the
parentheses in expressions like

(val & mask) != 0

and so on. Presumably this was done for compatibility reasons.

And yet Python manages to flip the priorities around
<http://docs.python.org/py3k/reference/expressions.html> (see sections 5.8
and 5.9) without tripping anybody up. In fact, for a long time, I wrote
expressions in Python with the parentheses as above. Then one day I happened
to make it

val & mask != 0

and actually didn’t notice at first; it was only in looking the code over
later did I realize I’d done this, and the code still worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top