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

bit, byte and int: 2-State Data Types

SystemVerilog Data Types

Runnable example from the SystemVerilog bit, byte and int tutorial (2-State Data Types)

Open in IDE
testbench.sv
module tb;
  bit   [3:0] var_b;      // Declare a 4-bit variable of type "bit"  
  logic [3:0] x_val;     // Declare a 4-bit variable of type "logic"
  
  initial begin  
    x_val = 4'b01zx;
  
    // If a logic type or any 4-state variable assigns its value to a "bit" type
    // variable, then X and Z get converted to zero
    var_b = x_val;
    $display ("x_val=%b var_b = %b", x_val, var_b);
  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.