Guest User

Untitled

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