Logic which takes four 8-bit patterns and outputs multiplexer code which can be used to select the two best patterns.

A) Each pattern is compared against the other three.

B) For each pattern, it is determined whether it is greater than two or not less than two of the other patterns, or whether it is greater than one and not less than another. Note that the logic naturally favors certain patterns in the case of a tie, because if two patterns are equal, then the compare between those two will output a logic 0, the same result had one pattern actually been less than the other. The result of this stage are 4 bits, two of which are high, representing the selected patterns.

C) The four bits from the last stage are converted to multiplexer code.