Created
April 5, 2017 19:18
Revisions
-
VojtaStavik created this gist
Apr 5, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ + (NSInteger) calculateHammingDistanceFor:(NSInteger)x and:(NSInteger)y { // Step 1: Find different bits NSUInteger differentBits = x ^ y; // Step 2: Count them NSUInteger counter = 0; while (differentBits > 0) { NSUInteger maskedBits = differentBits & 1; if (maskedBits != 0) { counter++; } differentBits = differentBits >> 1; } return counter; }