Prev Problem
Next Problem

68. 4-bit Comparator

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module maxmin4 (
    input [3:0] a, b, c, d,
    output reg [3:0] max, min
);
    reg [3:0] max1, max2, min1, min2;

    always @(*) begin
        max1 = (a > b) ? a : b;
        min1 = (a < b) ? a : b;

        max2 = (c > d) ? c : d;
        min2 = (c < d) ? c : d;
        
        max = (max1 > max2) ? max1 : max2;
        min = (min1 < min2) ? min1 : min2;
    end

endmodule

 

Was this helpful?
Upvote
Downvote