Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Cast Static: Bit-Width Truncation (Narrowing a Vector)

SystemVerilog Classes & OOP

Runnable example from the SystemVerilog Cast Static tutorial (Bit-Width Truncation (Narrowing a Vector))

Open in IDE
testbench.sv
module tb;
  bit [31:0] wide = 32'hDEAD_BEEF;
  bit [15:0] narrow;

  initial begin
    narrow = 16'(wide);
    $display ("narrow = 0x%0h", narrow);
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.