Altera® AXI4 Bus Functional Model User Guides

ID 838773
Date 5/19/2025
Public
Document Table of Contents

2.5.1.1.2. Utility Function num_formatter

The axi4_stream_bfm_types_pkg includes a simple num_formatter utility function that improves the simulation output readability for large numbers.

The header for num_formatter is:

function automatic string num_formatter (
   longint num, 
   string radix, 
   int width = 1
);

The input num is the value of the number for which you want to add separators for readability. Since the input is a longint, the maximum number of bits in the number being formatted is 64 bits.

The string radix is commonly set to the following:

  • d for decimal using comma “,” separator for every 3 digits.
  • b for binary using underscore “_” separator for every 4 digits.
  • h for hexadecimal using underscore “_” separator for every 4 digits.

The width is set to the minimum number of digits to show, which is one by default. However, if you want leading zeroes for a number like 16’h5, so that it appears as 0000_0005, then set the width to 8 (again, the number of digits).

The string return value is a formatted string form of the number that includes the separators. If the input number is not long enough to use separators after formatting with the appropriate radix and width, then no separators are inserted. Utility Function num_formatter Usage shows a simple example of the usage.

Figure 17. Utility Function num_formatter Usage