binarySearch = function(A, value) low = 0 high = A.len - 1 while true if high < low then return null mid = floor((low + high) / 2) if A[mid] > value then high = mid - 1 else if A[mid] < value then low = mid + 1 else return mid end if end while end function