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

File IO Operations: Formatting data to a string

Verilog Examples

Runnable example from the Verilog File IO Operations tutorial (Formatting data to a string)

Open in IDE
testbench.v
module tb;
  reg [8*19:0] str;
  reg [3:0] a, b;

  initial begin
    a = 4'hA;
    b = 4'hB;

    // Format 'a' and 'b' into a string given
    // by the format, and store into 'str' variable
    $sformat(str, "a=%0d b=0x%0h", a, b);
    $display("%0s", str);
  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.