Here you can find the source of binarySearch(int[] array, int size, int value)
static int binarySearch(int[] array, int size, int value)
//package com.java2s; //License from project: Apache License public class Main { static int binarySearch(int[] array, int size, int value) { int lo = 0; int hi = size - 1; while (lo <= hi) { int mid = (lo + hi) >>> 1; int midVal = array[mid]; if (midVal < value) { lo = mid + 1;/*w w w .ja v a 2 s .c om*/ } else if (midVal > value) { hi = mid - 1; } else { return mid; // value found } } return ~lo; // value not present } }