← ProblemsVerilog Language / More Verilog Features
Conditional ternary operator
36%conditionalsvectorsGiven four unsigned 8-bit numbers a, b, c, and d, output the minimum of the four.
Verilog's conditional (ternary) operator condition ? then : else works just like in C, and unlike an if statement it can be used inside a continuous assign. A clean approach is a small tournament: compare the numbers two at a time, keep the smaller of each pair in an intermediate wire, then compare the two winners.