HDLBits – Xnorgate

Create a module that implements an XNOR gate.

Note: The bitwise-XOR operator is ^. There is no logical-XOR operator.


This exercise is very similar to the NOR gate problem. We can implement the XNOR logic various ways. First, we’ll approach it the same way that we approached the NOR gate problem:

module top_module (
  input  logic a,
  input  logic b,
  output logic out );
  // Use bitwise operators for signal manipulation (~)
  assign out = ~(a ^ b);
endmodule : top_module

There is also shorthand notation for the XNOR operation, so we could do either of the following instead:

assign out = a ~^ b;
assign out = a ^~ b;

An important thing to remember here is that there is not a logical XOR operation. Also, note that this shortcut can not be applied to AND or OR operations, meaning that ~& or ~| will trigger compiler errors.

Leave a Reply

Your email address will not be published. Required fields are marked *