In reply to dave_59:
Thanks, Dave, I have changed the code to the following:
function void test_vars();
static int myInt = 32'h1200d2d5;
automatic string myString, myOtherString;
$display("myInt = %h", myInt);
// first cast
$sformat(myString, "%s", myInt);
// second cast
myOtherString = string'(myInt);
$displayh("myString = %p, myOtherString = %p", bytes_t'(myString), bytes_t'(myOtherString));
endfunction : test_vars
What I get is this:
myInt = 1200d2d5
myString = '{18, 32, -46, -43} , myOtherString = '{18, -46, -43}
While I would like to have seen this:
myString = '{18 , 00, -46, -43}
Still, the first cast is translating 0x00 to 0x20 (32 in decimal), while the second cast completely ignores the 0x00 byte.