All of the following code examples use an "inclusive" upper bound (i.e. The algorithms return the index of some element that equals the given value (if there are multiple such elements, it returns some arbitrary one). In such a situation however, preparing in-line code may be the better move: fortunately, there is not a lot of code involved.

It is also possible, when the element is not found, to return the "insertion point" for it (the index that the value would have if it were inserted into the array). There is no point in using an explicitly recursive version (even though the same actions may result during execution) because of the overhead of parameter passing and procedure entry/exit.

Recursive Pseudocode: The following algorithms return the leftmost place where the given element can be correctly inserted (and still maintain the sorted order). Later compilers offer features allowing the development of "generic" functions so that the same function name may be used yet the actual routine invoked will be selected according to how the parameters are integers or floating-point, and of different precisions.

Given the starting point of a range, the ending point of a range, and the "secret value", implement a binary search through a sorted integer array for a certain number. Changing the search to be for A(first:last) is trivial, but the "not-found" return protocol would require adjustment, as when starting the array indexing at zero.

Implementations can be recursive or iterative (both if you can). Aside from the "not found" report, The variables used in the search must be able to hold the values first - 1 and last 1 so for example with sixteen-bit two's complement integers the maximum value for last is 32766, not 32767.