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,
    input [3:0] b,
    input [3:0] c,
    input [3:0] d,
    output [3:0] max,
    output [3:0] min
);

wire [3:0] min01, max01, min23, max23;

assign {min01, max01} = (a < b) ? {a, b} : {b, a};
assign {min23, max23} = (c < d) ? {c, d} : {d, c};

assign max = (max01 < max23) ? max23 : max01;
assign min = (min01 < min23) ? min01 : min23;

endmodule

 

Was this helpful?
Upvote
Downvote