Example #1
0
        public static int GetHammingDistance(this byte[] x, byte[] y)
        {
            if (x.Length != y.Length)
            {
                throw new ArgumentException("values must be same length");
            }

            var distance = 0;

            for (var i = 0; i < x.Length; i++)
            {
                var value = (int)Xor.CompareBytes(x[i], y[i]);

                while (value != 0)
                {
                    distance++;
                    value &= value - 1;
                }
            }

            return(distance);
        }