input: Write a python function to find the closest number to a given number in a sorted list using binary search.
  assert closest_num([5, 4, 8, 7], 5)==5
  assert closest_num([5, 4, 8, 7], 6)==5
  assert closest_num([1, 2, 3, 4, 5], 3)==3
  assert closest_num([10, 20, 30, 40], 25)==20
output: def closest_num(sorted_list, target):
      left, right = 0, len(sorted_list) - 1
      closest = sorted_list[0]
  
      while left <= right:
          mid = (left + right) // 2
          if abs(sorted_list[mid] - target) < abs(closest - target):
              closest = sorted_list[mid]
          if sorted_list[mid] < target:
              left = mid + 1
          elif sorted_list[mid] > target:
              right = mid - 1
          else:
              return sorted_list[mid]
  
      return closest