Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 byte[] bitfield = new byte [0xFFFFFFF/8];
- 2 void findOpenNumber2() throws FileNotFoundException {
- 3 Scanner in = new Scanner(new FileReader(“input_file_q11_4.txt”));
- 4 while (in.hasNextInt()) {
- 5 int n = in.nextInt ();
- 6 /* Finds the corresponding number in the bitfield by using the
- 7 * OR operator to set the nth bit of a byte (e.g.. 10 would
- 8 * correspond to the 2nd bit of index 2 in the byte array). */
- 9 bitfield [n / 8] |= 1 << (n % 8);
- 10 }
- 11
- 12 for (int i = 0 ; i < bitfield.length; i++) {
- 13 for (int j = 0; j < 8; j++) {
- 14 /* Retrieves the individual bits of each byte. When 0 bit
- 15 * is found, finds the corresponding value. */
- 16 if ((bitfield[i] & (1 << j)) == 0) {
- 17 System.out.println (i * 8 + j);
- 18 return;
- 19 }
- 20 }
- 21 }
- 22 }
Add Comment
Please, Sign In to add comment