How to sign-extend a number in Verilog

You nearly got it…

always @( posedge clk ) begin
    extended[15:0] <= { {8{extend[7]}}, extend[7:0] };
end

You’re also missing a clock edge for the ’40’ test. Try this, & let me know how you get on…

Leave a Comment