the function to calculate hamming distance