4

I don't understand why some of the code example in the internet uses %0d to display the value of the variables and some of the code use %d? what are the difference between %0d and %d?

   data_1bit   = {32{4'b1111}};
   $display("data_1bit    = %0d",data_1bit);

   data_1bit_unsigned   = {32{4'b1111}};
   $display("data_1bit_unsigned  = %d",data_1bit_unsigned);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Kang Eik Han
  • 41
  • 1
  • 1
  • 3

2 Answers2

4

This is explained in section 21.2.1.3 Size of displayed data of the 1800-2012 LRM. %d displays using a fixed width to accommodate the largest possible value for the expression being displayed. %0d displays the minimum width, suppressing any leading 0's or spaces.

toolic
  • 57,801
  • 17
  • 75
  • 117
dave_59
  • 39,096
  • 3
  • 24
  • 63
1

It simply removes unnecessary spaces introduced by the display statements. See example below-:

module xyz;

  integer a;

  initial
  begin
    a=8;
    $display("Value of a using percent__d = %d", a);
    $display("Value of a using percent_0d = %0d", a);
  end

endmodule

OUTPUT

Value of a using percent__d =           8
Value of a using percent_0d = 8