function outind = binsearch(vec, key)

low = 1;
high = length(vec);
outind = -1;
while low <= high && outind == -1
   mid = floor((low+high)/2);
   if vec(mid) == key
      outind = mid;
   elseif key < vec(mid)
      high = mid-1;
   else
      low = mid+1;
   end
end

