Operators
Simple summary of operators in Java.
Bitwise operators
AND
AND operator produces 1
only if both numbers are 1
. So, 1 | 2
should produce 0
. On the other hand, 1 | 3
should print 1
, becuase they will have one 1
in common (then 1 in the middle of that binary number).
OR
001 OR 010
will result in 011
, which is 3. Also 011 OR 011
will result in the same number. Because you need to take each binary number and apply OR. Lets take 1 and 0 from the first example, that are on zeroth position, 001 and 010, 1 OR 0
results in 1. 1 OR 1
results in 1. 0 OR 1
results in 1.
Last updated
Was this helpful?