Say I'm given a vector wire large_bus[63:0] of width 64. How can I XOR the individual signals together without writing them all out:

assign XOR_value = large_bus[0] ^ large_bus[1] ^ ... ^ large_bus[63] ?

I'm especially interested in doing this for vectors where the width is specified by a localparam.


Binary operators like &, |, ^ and some others can also be unary in verilog, which is quite convenient. They perform bitwise operations on the operand and return a single bit value. See e.g. reduction operators on asic-world.com.

reg [63:0] large_bus;

wire xor_value;
assign xor_value = ^large_bus;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.