Good morning,
I am given the hamming distance algorithm in C which is
I see that this loop counts all the 1's that are found when we xor y and x, but what I'm puzzled with is how does the while loop break out? How does it know when a value is complete?Code:int returnDistance(int x, int y) { unsigned dist = 0; unsigned val = x ^ y; while(val) { ++dist; val &= val - 1; } return dist; }
Thanks.