How to print hexadecimal numbers in upper case

In system verilog, when we use $display to print hex numbers, they are in lower case. For example, the following statement:

$display("var=%0h", var)

will get “var=af”.
How can I get “var=AF” with $display?

Hello!
Try one of these 2 methods (or both) and get back to me as I’ve done this on Python and not in SV.

  1. $display(“var = %0h{:H}”, var);
  2. $display(“var = %0H”, var);

Please inform if both are working or aren’t or if any one is working.

Hope it helps.

In reply to Aaron_Cui:

SystemVerilog has a toupper() string method.

module top;
   logic [15:0] val = 16'hcafe;
   string sval;
   initial begin
      sval.hextoa(val);
      $display("val= %s", sval.toupper());
   end
endmodule

1 Like

In reply to Shashank Gurijala:

Hi Mr. Gurijala,

Thanks for your reply. Bad news that neither method works.

In reply to dave_59:

Hi Mr. Rich,

Thanks for your reply! Seems that this is the only way.

In reply to Aaron_Cui:

Sorry :(

In reply to dave_59:

Hi Dave!
Thanks for the solution. But is there a function to convert uppercase letters to lowercase?

In reply to Shashank Gurijala:

See section 6.16 String data type in the IEEE 1800-2017 SystemVerilog LRM.