code: private static int binarySearch(int[] array, int toIndex, int key) {
          int low = 0;
          int high = toIndex - 1;
  
          while (low <= high) {
              int mid = (low + high) >>> 1;
              int midVal = array[mid];
  
              if (midVal < key) {
                  low = mid + 1;
              } else if (midVal > key) {
                  high = mid - 1;
              } else {
                  return mid; // key found
              }
          }
          return -(low + 1);  // key not found.
      }
docs: Realisation of binary search algorithm. It is in JDK 1.6.0 but for
  JDK 1.5.0 compatibility I added it there.
  
  @param array   array of integers values ordered by ascending
  @param toIndex top break of array
  @param key     searched value
  @return value index or -(index of position)