HDLBits – Vector4

Build a circuit that sign-extends an 8-bit number to 32 bits. This requires a concatenation of 24 copies of the sign bit (i.e., replicate bit[7] 24 times) followed by the 8-bit number itself.


The main takeaway for this exercise is that the replication operator can be used to duplicate signals to aid in signal manipulation:

module top_module (
  input  logic  [7:0] in,
  output logic [31:0] out );
  assign out = { { 24{in[7]} }, in };
endmodule : top_module

Leave a Reply

Your email address will not be published. Required fields are marked *