Sped up hamming dist function for Q2 P2