input: Write a python function to perform a binary search on a sorted array.
  assert binary_search([2, 3, 4, 10, 40], 10) == 3
  assert binary_search([1, 2, 3, 4, 5, 6, 7, 8, 9], 7) == 6
  assert binary_search([5, 10, 15, 20, 25], 15) == 2
  assert binary_search([10, 20, 30, 40, 50], 25) == -1
  assert binary_search([], 1) == -1
output: def binary_search(arr, x):
      left, right = 0, len(arr) - 1
      while left <= right:
          mid = (left + right) // 2
          if arr[mid] == x:
              return mid
          elif arr[mid] < x:
              left = mid + 1
          else:
              right = mid - 1
      return -1