We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The reference page says that the bitwise AND operator & can be used with variable type int, but when you try it you get an error. Any idea what is going on? Is it Processing, the reference page or me? Processing 3.3.3 on a Mac Thanks
Answers
Post the statement giving the error.
This works in C
maybe like this? I dunno.
In your version your & might be treated as &&
The problem appears to be that Processing has evaluated the
0x01 == 0
first and then tries to do the bitwise & between an int and a boolean. The solution is to use parentheses to clarify the operedr of evaluation like thisLike every1 said above. Just an extra info:
& 1
is used to determine whether a value is even or odd: B-)Another curious case in Java: Operators
&
,|
and^
are overloaded to acceptboolean
operands:if (mouseX > width>>2 & mouseX < 3*width/4) println("Active region");
:)>-However, both sides of the bitwise operators are always eagerly evaluated. L-)
Unlike their logical counterparts
&&
and||
, which are lazy-evaluated and short-circuits the right side if the result can already be determined by just the left side operand. :-BThanks guys that did it.
the actual error message is
"The operator & is undefined for the argument type(s) int, boolean"
things are so much easier when people give the exact error message.