Find minimum XOR values in a given array I am implementing an algorithm to find the pair of integers in the given array which have minimum XOR value.

Ex:

Input:

   0 2 5 7


Output:

   2 (value of 0 XOR 2).


Then bellow is my solution:

    public int findMinXor(List&lt;int&gt; A)
    {
        var min = int.MaxValue;

        for (int i = 0; i &lt; A.Count - 1; i++)
        {
            for (int j = i + 1; j &lt; A.Count; j++)
            {
                var tmp = A[i] ^ A[j];

                if (tmp &lt; min)
                {
                    min = tmp;
                }

            }
        }

        return min;
    }


What should I do to improve the solution (clean code, performance, DRY,...)?
Any help are appriciate!
The program is running in quadratic time. As usual, to improve performance you need to change the algorithm.

Sort the numbers into 32 buckets, according to where the most significant bit of the number is. Convince yourself that if a bucket contains more than one number, it makes no sense to test them against the numbers from other buckets (the result is guaranteed to not be minimal). A cross-bucket xor should be tested only if two adjacent buckets contain just one number each.

Work recursively with each bucket.