Iterative binary search Binary search is an algorithm that looks for an element in a sorted data-structure by constantly dividing the search space in half.
Rosetta Code

A binary search divides a range of values into halves, and continues to narrow down the field of search until the unknown value is found. It is the classic example of a &quot;divide and conquer&quot; algorithm.

Wikipedia

In computer science, a binary search or half-interval search algorithm finds the position of a target value within a sorted array. The binary search algorithm can be classified as a dichotomic divide-and-conquer search algorithm and executes in logarithmic time.


Smallest # of bytes wins
Clarifications

Example of calling the function/lambda/macro should be included, but don't count those chars!
Output should be &gt; -1 if found, and &lt;=-1 otherwise
import binary_search (20 bytes) DOES NOT count!
Implementation should run in O(log n), as algorithm dictates

Also see the code-golf StackExchange FAQ.
Example
&gt; binary_search([1,3,5,6,7,8,8,10], 5);
4
&gt; binary_search([1,3,5,6,7,8,8,10], 543);
-1
JavaScript (94 bytes)

(a,e)=&gt;{u=a.length,m=0;for(l=0;l&lt;=u;)e&gt;a[m=(l+u)&gt;&gt;1]?l=m+1:u=e==a[m]?-2:m-1;return u==-2?m:-1}


Expanded out a little so you can see what's going on:

function binary_search(array, elem) {
    let u = array.length, m;
    for (let l = 0; l &lt;= u;)
        if (elem &gt; array[(m = (l + u) &gt;&gt; 1)]) l = m + 1;
        else u = (elem == array[m]) ? -2 : m - 1;
    return (u == -2) ? m : -1;
}


Example usage:

&gt; a = [1,2,3,4,5,6,7,8,9,10]
&gt; binary_search(a, 5)
4
&gt; binary_search(a, 15)
-1