根据符号位进行判断,如果为1则需要按位求反加1,否则保持原状
module OToC_code(
input [4:0] a,
output [4:0] out
);
assign out = (a[4] == 1)?({a[4],~a[3:0]}+1):a;
endmodule
测试代码
module tb_Code;
// Inputs
reg [4:0] a;
// Outputs
wire [4:0] out;
// Instantiate the Unit Under Test (UUT)
OToC_code uut (
.a(a),
.out(out)
);
initial begin
// Initialize Inputs
a = 0;
// Wait 100 ns for global reset to finish
#100 a = 5'b10010;
#100 a = 5'b01111;
// Add stimulus here
end
endmodule