Re #8033. Change to a linear search to a binary one.

And use a standard algorithm instead of home-brewing it.
Re #8033. Update comments.
Merge remote-tracking branch 'origin/feature/8033_getbinindex_binary_search'