public static boolean binarySearch(int[] arr, int val) {
        boolean found = false;
        if (arr == null||arr.length == 0||val < arr[0]||val > arr[arr.length-1]) return found;
        int lo = 0;
        int hi = arr.length;
        int mid; // = (hi - lo)/2;
        while (lo <= hi) {
            mid = lo + ((hi - lo)/2);
            if (val == arr[mid]) {
                found = true;
                break;
            } else if (val > arr[mid]) {
                lo = mid + 1;
            } else {
                hi = mid - 1;
            }
        }
        return found;
    }