This is a bit tricky, it's a nice challenge for those up to the task I think. And I did search through all the questions previously asked, but I couldn't find what I want.
The aim here is, given 2 integers written in binary on n bits, to find the greatest one of them using only logic operations (AND, OR, ...) on the n bits of each integer (result would be 0 if the first integer is the greatest, and 1 otherwise). Ultimately, the aim is to be able to draw an electronic circuit where the 2*n bits would be wires with or without tension, and plug the wires into actual electronic components that would perform logical operations.
I started thinking about this problem by realizing that whatever happens (i.e. whatever n is), 2^n is greater 2^0 + ... + 2^(n-1) (mathematically speaking, that's easy to come up with). That means that whichever integer has a bit (say number k) that's at 1 when the corresponding bit in the other integer is 0, with all other bits between n and k (all bits to the left of k) identical, is the greatest. Example :
A : 010(1)1011 is greater than B : 010(0)1111 with the significant bit in parentheses. All bits to its left are identical, and we don't have to care about the others.
So one can perform an exclusive OR (XOR) on all pairs of bits : the significant one would yield a 1, and then I can perform a NAND between corresponding bit of A with the result of that XOR, so that it'd yield a 0 if A's k-th bit is a 1 and a 1 if it's B's k-th bit that is a 1. The only thing is ... what about the bits to the right of the significant one ? They can be different (thus also yielding a 1 when performing a XOR) but I have to ignore that ... Any ideas ?