updated binary search

Here is the Python version for Testing:

def bins(x, x_insert, imin, imax):
    if (x_insert < x[imin] or x_insert > x[imax]):
        print('out of bounds')
    else:
        while (imin <= imax):
            imid = imin + (imax - imin) / 2
            if (x[imid] > x_insert):
                imax = imid - 1
            else:
                imin = imid + 1
        return imin - 1