0b0101_0101 & 0b0001_1100 → 0b0001_0100
& logical AND is a logical carryless bitwise multiply, used for masking (getting rid of parts of a word you don’t want), 1s where both operands have a 1 otherwise 0. Don’t confuse this with &&.
0 & 0 →
0
0 & 1 →
0
1 & 0 →
0
1 & 1 →
1
boolean isPowerOfTwo = (n & -n) == n;
Here is how to and together an array of booleans:
|
|
You can get the freshest copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) |
| http://mindprod.com/jgloss/andoperator.html | J:\mindprod\jgloss\andoperator.html | |
![]() | ||
| Canadian Mind Products | ||
| mindprod.com IP:[65.110.21.43] | ||
| view Blog | Your face IP:[38.107.179.210] | |
| Feedback | You are visitor number 11. | |