Equality

keysymbols: ==, !=, ===, !==.

The equality operators are logical equality, logical inequality, case equality and case inequality. These operators compare the operands bit-by-corresponding-bit for equality.

The logical operators will return unknown if "significant" bits are unknown or high-impedence (x or z)

The case operators look for "equality" also with respect to bits which are unknown or high impedence.

If one operand is shorter than the other, it is expanded with 0s unless the most significant bit is unknown.

        module equTest;
           reg [3:0] a, b ,c, d, e, f;

           initial begin
              a = 4; b = 7;    // these default to decimal bases
              c = 4'b010;
              d = 4'bx10;
              e = 4'bx101;
              f = 4'bxx01;

              $displayb(c);      // outputs 0010
              $displayb(d);      // outputs xx10

              $display(a == b);  // logical equality, evaluates to 0
              $display(c != d);  // logical inequality, evaluates to x
              $display(c != f);  // logical inequality, evaluates to 1
              $display(d === e); // case equality, evaluates to 0
              $display(c !== d); // case inequality, evaluates to 1
           end
        endmodule // equTest

EXERCISE
What do the following evaluate to ?

              $displayb(3'b101 != 3'b010);
              $displayb(4'b0001 == 4'b1);
              $displayb(4'b101x == 4'b101x);
              $displayb(4'b101x === 4'b101x);

Answers


previous next contents