# Thread: Binary numbers

1. ## Binary numbers

An (sorted) array consists of (a random amount of) random unique integers between 0 and 2^32 - 1.

In base 2 the array could, for example, look like this:

Code:
00000000000000000000000000000100
00000000000000000000000000000110
00000000000000000000000000010010
...
11111111111011011111100101001100
Given another random integer x between 0 and 2^32 - 1, how do I find the integer in the array that shares the most ones and zeros with x in the same position (in binary notation)? If there are multiple cases, any of the cases will do.

The following two numbers will, for example, differ in only one place:

Code:
00000000000000000000000000010010
00000000000000000000000000110010
I cannot check them one at a time, I need to do it faster. A binary search-style approach would be perfect.

Feel free to transform the array and x into something else.