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

Streaming Operators: Packing Values Into a Stream

SystemVerilog Arrays

Runnable example from the SystemVerilog Streaming Operators tutorial (Packing Values Into a Stream)

Open in IDE
testbench.sv
module tb;
  initial begin
    int j = { "A", "B", "C", "D" };   // packs to 32'h41424344

    bit [31:0] s1 = { >>      { j } };  // same bit order, unchanged
    bit [31:0] s2 = { << byte { j } };  // byte order reversed
    bit [31:0] s3 = { << 16   { j } };  // 16-bit halves swapped

    $display("j  = 0x%0h", j);
    $display("s1 = 0x%0h", s1);
    $display("s2 = 0x%0h", s2);
    $display("s3 = 0x%0h", s3);
  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.