char chess = _board[0];
for (char i = 1; i < 9; ++i)
{
chess &= _board[i]; //?
}
board is a 1-d char array. what does chess& = board[i] mean? Thank you.
The following statement:
x &= y
... is equivalent to:
x = x & y
... and, in the above, the ampersand (&) is the "bitwise and". The result of "x & y" is a value that has a 1 in all the bits where both x and y have corresponding 1 bits, and everywhere else the bits are 0.
&= is the compound bitwise AND and assignment operator. What it does is that it takes the bits in chess (which is 8 bits as a char) and ANDs them with the corresponding bits of _board[i]. Then it assigns the results back to chess.
In effect, together with the loop this causes each bit of chess to be set if all of the values in _board has the corresponding bit set.
Further: since _board is 8 items times 8 bits, I 'll assume that each item represents a row and the bits of the item represent the columns a-h of that row. The presence of an 1 in a bit position represents something (we don't know what).
So the end result would be that chess contains an 1 in each of its 8 bits if and only if the something exists all rows on the corresponding column a-h of the chessboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With