In minecraft, how do I construct a 4-bit comparator?

Solution 1:

While it's possible to build a contraption that operates on discrete boolean arithmetics, built of logic gates, it would be terribly impractical; you have some 5 gates per bit, each gate a good couple blocks, cross-connections, this would be quite awful. Luckily, for arithmetics on numbers up to 4 bits, Minecraft provides a much handier and more graceful tool - analog redstone; use of signal strengths and the comparator.

This is the device that meets the requirements as stated (shown state: "15 > 14", green input greater than blue.):

enter image description here enter image description here enter image description here

It looks bulky, but that's only due to need to "massage" the problem as stated (binary input, outputs of "<,=") into what works naturally in Minecraft (analog inputs and outputs of "<,>"). If you take the Minecraft-natural approach all you need is the "core" of 2 comparators:

enter image description here

In this case, you deliver two signals of varying strength, X,Y. The outputs are their difference X-Y and Y-X if the result is positive; no output if zero or less.

What the "extended" version does is first convert 4 input bits into analog signal (through subtracting 1,2,4 or 8 respectively; in Minecraft analog circuitry all addition is done as a + b = 15 - (15 - a - b))*, then compared; then the two outputs are fed downwards into a NOR gate, to produce output if neither is active, meaning the inputs are equal. If you skip the repeaters on output, your output will contain magnitude of the difference too.

*The inputs aren't normalized back to the original value 15 - (15 - x), just fed into the comparator in the 15-complement form 15 - x, as this compacts the contraption; instead of reversing the values, I'm just flipping the meaning of the outputs; if x < y, then (15 - x) > (15 - y)