How to concatenate decimal or hex values with the string name?

Hi All,

I have one scenario in which I am trying to concatenate hex values with the string but I am not seeing the intended string while
printing it.

Example code:

string reg_name;
reg_offset = 'h5060
reg_name = {reg_offset, "_REG_RD"};

I am expecting the print to be 5060_REG_RD but I am seeing something like this “pL_REG_RD”.
Is there any other way to get it done?

Thanks in advance
Prashanth

In reply to prashanth.billava:
I assume reg_offset is a bit vector. You need to convert its value to a hex representation in a string of ASCII characters.

You can do that with with either a string function

reg_name.hextoa(reg_offset)
reg_name = {reg_name, "_REG_RD"};

a system task

$sformat(reg_name,"%0h_REG_RD",reg_offset);

or a system function

reg_name = {$sformatf("%0h",reg_name), "_REG_RD"};

In reply to dave_59:

In reply to prashanth.billava:
I assume reg_offset is a bit vector. You need to convert its value to a hex representation in a string of ASCII characters.
You can do that with with either a string function

reg_name.hextoa(reg_offset)
reg_name = {reg_name, "_REG_RD"};

a system task

$sformat(reg_name,"%0h_REG_RD",reg_offset);

or a system function

reg_name = {$sformatf("%0h",reg_name), "_REG_RD"};

Thanks Dave. I used the first solution as I was concatenating and assigning it to string field of the transaction item.

Hi Dave,
I am using the first solution that you mentioned above to concatenate two strings.

But currently I am facing some issue to convert the string into capital alphabets.The issue is described as follows.

Let us suppose I have 'h00c value that I need to concatenate with some string “register_”.
But my requirement is I need a string “register_00C” as output(C should be in capital).

I have tried the following solution but it doesn’t works.
I am able to get the string “register_00c” by concatenation method.But as I need the capital C,I converted “00c” string into capital but in that case the result I am getting is " C" i.e the zeros are replaced by spaces.

If I pass 'h00C in hexadecimal it automatically considers it as 'h00c.

So do you have any solution about this.

In reply to dave_59:
Dave. Option 2 worked great. Thanks for that answer.