Prev Problem
Next Problem

42. Equality Operators

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

// 2-bit X Pattern Detector using Equality Operators
module x_detector (
  input  wire [1:0] a,
  output reg  eq_logic,
  output reg  eq_case
);

  always @(*) begin
    // Logical equality (==) treats 'x' or 'z' as unknown → result may be 'x'
    eq_logic = (a == 2'bx1);

    // Case equality (===) treats 'x' and 'z' as valid bits → gives definite 1 or 0
    eq_case  = (a === 2'bx1);
  end

endmodule

 

Was this helpful?
Upvote
Downvote