Here is a Python code that performs the steps you described:

```python
def binary_search(x, a):
    low = 0
    high = len(x) - 1

    while low <= high:
        mid = (low + high) // 2

        if x[mid] == a:
            return mid
        elif x[mid] < a:
            low = mid + 1
        else:
            high = mid - 1

    if low < len(x) and x[low] == a:
        return low
    elif high >= 0 and x[high] == a:
        return high
    else:
        return -1

# Example usage:
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a = 5
result = binary_search(x, a)

if result != -1:
    print(f"Element {a} found at position {result}")
else:
    print(f"Element {a} not found in the list")
```

This code uses a binary search algorithm to find the element `a` in the sorted list `x`. It repeatedly divides the search interval in half and searches for the element in the appropriate half until it is found or the search interval is empty.

The time complexity of this algorithm is O(log n), where n is the length of the list `x`. This is because the algorithm divides the search interval in half at each step, resulting in a logarithmic number of steps.

Note that this code assumes that the list `x` is sorted in ascending order. If the list is not sorted, the algorithm may not work correctly.