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

Conversion Functions: Passing Real Values Through Ports

Verilog Examples

Runnable example from the Verilog Conversion Functions tutorial (Passing Real Values Through Ports)

Open in IDE
testbench.v
module sensor_model (output [63:0] temp_bits);
  real temperature;
  initial temperature = 36.6;
  assign temp_bits = $realtobits(temperature);
endmodule

module monitor (input [63:0] temp_bits);
  always @(temp_bits)
    $display("Temperature = %0.1f", $bitstoreal(temp_bits));
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.