不同位宽操作数按位与,低位的未定义位会自动补0
---IEEE Standard for Verilog® Hardware Description Language
例子:
测试代码
module test(
input [7:0] a,
input [7:0] b,
input sel,
output [7:0] out1,
output [7:0] out2
);
assign out1 = (sel & a);
assign out2 = (~sel & b) ;
endmodule
//testbench
`timescale 1ns / 1ns
module tbtest;
reg [7:0] a;
reg [7:0] b;
reg sel;
wire [7:0] out1;
wire [7:0] out2;
initial begin
a = 8'b1010_1010;
b = 8'b1011_1011;
sel = 1'b1;
end
test DUT(a, b, sel, out1, out2);
endmodule
测试波形:
(sel & a) 等价于
0000_0001 & 1010_1010 ==> 00000000 == out1
(~sel & b) 等价于
1111_1110 & 1011_1011 ==> 1011_1010 == out2
这里的sel先进行了补零,再进行了~操作