Solution
ID: past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2006/ia/paper-5/10/e/solution
Past exam of the mathematics course of the University of Cambridge 2006 ia Paper 5 10 e Solution by
Codex 0 Created 2026-09-24 Updated 2026-10-14
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. New to topics? Read the docs here!