Interested In VHDL Training? Click Here

0 votes
in Verilog by (200 points)

What is a xor and how do you code a xor in Verilog?

3 Answers

0 votes
by (220 points)

An 'exclusive or' that is a logical operation that outputs true or 1 only when inputs differ: 0 xor 1 = 1, 1 xor 1 = 0, true xor false = true, etc

This function is defined as the ^ operator in Verilog and is defined both for scalar and vector data types and may be a binary operator as well as an unary operator.

a 'xor' b is coded as a ^ b in Verilog.

0 votes
by (240 points)

XOR gate is an exclusive-OR gate. The output is high only when one and only one of the inputs is high. If both inputs are high or if both inputs are low then the output is also low. There are several methods to code an XOR. Behavourial modelling is shown below:

module xor_bm(c,a,b);
input a,b;
output c;
reg c;

if (a==0 & b==0)
else if (a==1 & b==1)
As mentioned earlier, when both inputs are the same (either both are high or both are low) then the output is low, otherwise it is high.

Another way to code an XOR is use the inbuilt verilog operator:
module xor_ex2(c,a,b); 
input a,b;
output c;
assign c=(a^b);
0 votes
by (200 points)

Xor is an operation: there are two types of xor, xor bit and xor array.

Xor bit: the result is 1 if the value of two inputs is different. And 0 if the value is same.

It's similar with an array by using xor bit per bit.

Want to improve your VHDL skills?

Click Here - Sign Up For VHDL Training

© 2022 by Hardware Coder. User contributions are licensed under cc by-sa 4.0 with attribution required. Attribution means a link to the question, answer, user, etc on this site.

This site is owned and operated by Hardware Coder in McKinney, Texas.

Send Us A Message
About Us

By using this site, you agree to the following:

Privacy Policy
Terms and Conditions
DMCA Policy
Earnings Disclaimer
Legal Disclaimer