Choose bit zero of each integer to represent the leftmost cell in its group of 32 columns. Then use a quotient to choose the word and a remainder to choose the bit:For valid ,
java
static boolean getBit(int[][] board, int i, int j) {
return ((board[i][j >>> 5] >>> (j & 31)) & 1) != 0;
}j >>> 5 is and ranges from zero to 31. The bit mask j & 31 is the offset . The logical right bit shift brings the desired bit to position zero; the final mask selects only that bit. Even bit 31 of a negative stored word is extracted correctly, because >>> inserts zeros. A different convention, with the leftmost cell in the most significant bit, would instead shift by 31 - (j & 31) and must be used consistently. Articles by others on the same topic
There are currently no matching articles.