Reduction Operator

Keysymbols: &, ~&, |, ~|, ^, ~^, ^~.

The reduction operators are and, nand, or, nor, xor xnor and an alternative xnor. They take one operand and perform a bit-by-next-bit operation, starting with the two leftmost bits, giving a 1-bit result.

        module reductTest;
           reg [3:0] a, b ,c;

           initial begin
              a = 4'b1111;
              b = 4'b0101;
              c = 4'b0011;

              $displayb(& a); // bitwise and, (same as 1&1&1&1), evaluates to 1
              $displayb(| b); // bitwise  or, (same as 0|1|0|1), evaluates to 1
              $displayb(^ b); // bitwise xor, (same as 0^1^0^1), evaluates to 0
           end

        endmodule // reductTest

Note: the bitwise xor and xnor are useful in generating parity checks.

Please note carefully the differences in logical, bitwise and reduction operators. The symbols for bitwise and reduction overlap but the number of operands is different in those cases.

EXERCISE
What do the following evaluate to ?


              $displayb(& 1'b10);
              $displayb(| 3'b101x);
              $displayb(^ 4'b1101);

Answers


previous next contents