| | and && are logical operators, so you can apply them to a condition only (that are boolean type in
java).
| and & operators are bitwise, they produce integer result.
if ((a==0) | | (b==0)) // true if b is 0 OR a is 0
if ((a>b) && (b<0)) // true if a greater then b AND b less than zero
As for bitwise operators, there is a standart approach for telling what they mean.
Each bit in left operand compared to the same bit in the right operand and depeding on this two values result is created.
left bit | right bit | & | | |
------------------------------
0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 |
1 | 0 | 0 | 1 |
1 | 1 | 1 | 1 |
==============================
Actually, this operators have the same idea. If you
take (0) as (false) and (1) as (true) you'll see that the
logic is the same.
0xf & 0x0 == 0x0
1111 &
0000 =
0000
0x5 | 0xa == 0xf
0101 |
1010 =
1111
------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )