improved binary search
wrote hamming distance function