input: Write a function to determine if a given value can be found in a sorted list of numbers using the binary search algorithm. If the value is found, return its index; otherwise, return -1. Implement this function in Python and verify its correctness with given test cases.
  assert binary_search([3, 4, 5, 6, 7, 8, 9], 8) == 5
  assert binary_search([3, 4, 5, 6, 7, 8, 9], 2) == -1
  assert binary_search([], 5) == -1
  assert binary_search([1], 1) == 0
  assert binary_search([1, 2, 3, 4, 5, 6], 4) == 3
output: def binary_search(arr, target):
      left, right = 0, len(arr) - 1
      while left <= right:
          mid = (left + right) // 2
          if arr[mid] == target:
              return mid
          elif arr[mid] < target:
              left = mid + 1
          else:
              right = mid - 1
      return -1