How to display/print unpacked type as hexadecimal in SystemVerilog?

Viewed 4480

I have an unpacked int array:

int wanna_print [];
wanna_print = new[1];

It can be printed like this:

$display("in hex: c86E [in dec: 51310] == %p", wanna_print[0]);

It will print it in decimal, but I need it in hexadecimal.

I tried %0h, %h instead of %p, but it gives this error:

Argument number 2 is an unpacked type, and may only be printed with the '%p' format.

How can I print it in hexadecimal? Can %p maybe somehow extended?

I tried $sformatf too, but it behaves the same.

1 Answers

Using $displayh works for me with VCS:

module tb;

int wanna_print [];

initial begin
    wanna_print = new[1];
    wanna_print[0] = 51310;
    $displayh("in hex: c86E [in dec: 51310] == %p", wanna_print[0]);
end

endmodule

Outputs:

in hex: c86E [in dec: 51310] == 0000c86e

$displayh is described in IEEE Std 1800-2017, section 21.2.1.2 Format specifications.

I get a compile error with Cadence, however.

Related