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

/*Write your code here*/
module maxmin4(a,b,c,d,max,min);
input [3:0] a,b,c,d;
output reg [3:0] max,min;
always @(*)  begin 
    if(a>=b&&a>=c&&a>=d) 
    max=a;
    else if(b>=a&&b>=c&&b>=d)
    max=b;
    else if(c>=a&&c>=b&&c>=d)
    max=c;
    else 
    max=d;

    if(a<=b&&a<=c&&a<=d) 
     min=a;
    else if(b<=a&&b<=c&&b<=d)
    min=b;
    else if(c<=a&&c<=b&&c<=d)
    min=c;
    else 
    min=d;
end
endmodule 

 

Was this helpful?
Upvote
Downvote