Raviteja
Raviteja

Reputation: 35

how to concatenate bit with a string in system verilog?

if(ci.busy) begin// writing
    **dataout** = {dataout,string'(**ci.dout**)};
    $sformat( request,"%b",req.dout );
    $fwrite(data, request);
end

here ci.dout is bit and dataout is string. This is the code I was using to convert bit to string using static casting. But the output of dataout at the end of test is 0. I would really appreciate help.

Upvotes: 0

Views: 6552

Answers (1)

Greg
Greg

Reputation: 19104

Casting with string'() will use ci.dout as the ASCII code of a string. For example, string'(8'h41) is "A", and string'(88'h48656C6C6F20576F726C64) is "Hello World"

Any of the following will work for you:

  1. dataout = {dataout,$sformatf("%b", ci.dout)};
  2. dataout = $sformatf("%s%b", dataout, ci.dout);
  3. $sformat(dataout, "%s%b", dataout, ci.dout);

Upvotes: 3

Related Questions