public int search(int value) {
        int startIndex = 0;
        int endIndex = orderedArray.length;

        while (true) {
            int middleIndex = (startIndex + endIndex) / 2;
            int middleValue = orderedArray[middleIndex];

            if (middleValue == value)
                return middleIndex;
            else if (endIndex < startIndex)
                return -1;
            else {
                if (value < middleValue)
                    endIndex = middleIndex - 1;
                else
                    startIndex = middleIndex + 1;
            }
        }
    }