module examples ();
string j =“123”;
initial
begin
$display("my_name getting value integer to ASCII = %s " j.atoi());
end
endmodule
output : 123
I am getting both the values same. So, my query is how this method atoi() works ?
module examples ();
string j =“123”;
initial
begin
$display("my_name getting value integer to ASCII = %s " j.atoi());
end
endmodule
output : 123
I am getting both the values same. So, my query is how this method atoi() works ?
In reply to mrudang pujari1:
Are you saying when you run the above code you’re seeing
my_name getting value integer to ASCII = 123
? Because that’s not what I’m seeing or what’s expected.
In reply to sbellock:
yes it’s same for all like . i.e. atoi,itoa,hextoa,bintoa ;
whatever value you will give to this function that will give same value in output.
I’m very confuse about this functions.
In reply to mrudang pujari1:
I’m not seeing that. I get the ASCII character “{”, which has the decimal code 123. That is the correct behavior after fixing the typo in your $display statement (missing ,). Perhaps there might be other typos.
In reply to dave_59:
thank you so much i have got that!
In reply to dave_59:
I am seeing a similar issue. I am trying to convert string to ascii & from its ascii code,back to string. I keep getting 0 irrespective of the string I pass. Could you help ?
class stringascii;
string str ="wait";
function try();
int a;
string s;
a=str.atoi();
$display("ascii formant of str %s is %d",str,a);
s.itoa(a);
$display("string format from asci is %s",s);
endfunction
endclass
module tb;
stringascii s1;
initial begin
s1=new();
s1.try;
end
endmodule
In reply to verif_gal:
Please look at the LRM about this method "It returns zero if no digits were encountered. It does not parse the full syntax for integer literals (sign, size, apostrophe, base). — atohex interprets the string as hexadecimal. — atooct interprets the string as octal. — atobin interprets the string as binary. NOTE—These ASCII conversion functions return a 32-bit integer value. Truncation is possible without warning. For converting integer values greater than 32 bits, see $sscanf in 21.3.4 . "
I wonder what is your expectation from the code shared, if you use any string using digits the code should work.
Maybe you are looking for “6.16.3 Getc() function byte getc(int i); — str.getc(i) returns the ASCII code of the ith character in str.”
HTH,
-R