Code:
static boolean won[] = new boolean[1 << 9];
It makes an array of
512 booleans.
That's because:
Code:
<< 0000000000000001
= 0000001000000000
And
0000001000000000 is binaries equivelant of decimals
512.
Code:
static final int DONE = (1 << 9) - 1;
It initializes DONE with a value of
511.
Look above. Afterwards, you simply subtracts one from the result.
Code:
if ((i & pos) == pos) {
Let's suppose
i is
11 and
pos is
12. Then the first calculation will give
8, and that's not equivelant to
pos.
That's because:
Code:
1011 [11]
& 1100 [12]
= 1000 [08]
Code:
...
isWon((1 << 3) | (1 << 4) | (1 << 5));
...
This will pass
56 to the function,
isWon.
That's because:
Code:
<< 00000001
= 00001000
<< 00000001
= 00010000
<< 00000001
= 00100000
------------
00001000
| 00010000
| 00100000
= 00111000
It looks like the coder only made the code in that way, to confuse the reader. It's a stupid way to code, and it's only annoying to look at. Sometimes it's good to do bit manipulation, but I see no reasons to do it in your example.