text to binary

R

raghu

Guest
Is it possible to convert a text message into a binary format using
verilog language???

Thanks a lot.

Regards,
Raghu
 
May be yes, with %u format - but why would you want to do that? Isn't
Perl/C better fit? What exactly are you trying to do?

Ajeetha, CVC
www.noveldv.com

raghu wrote:
Is it possible to convert a text message into a binary format using
verilog language???

Thanks a lot.

Regards,
Raghu
 
I would like to give the binary output of text message as an input to
an algorithm which i have implemented using verilog.
can you please suggest me how to convert the text to binary.

Hoping for a positive response.

Thanks a lot.

Regards,
Raghu
 
raghu wrote:
I would like to give the binary output of text message as an input to
an algorithm which i have implemented using verilog.
can you please suggest me how to convert the text to binary.
You may need to describe more precisely what you are trying to do,
since an English description is not entirely clear.

You have some text. If it is in a file, you can read it with a %s
format into a reg. If it is already in a reg, then you can skip that
step. At this point, the reg contains binary bits that represent the
ASCII encoding of the text characters. If that is what you mean by
converting it to binary, then you don't have to do anything. That is
already how it is stored. Your Verilog algorithm can operate on the
contents of the reg.

If you want to do something else, then you need to describe it more
precisely.
 
Thanks a lot for your valuable response.
As you said that a text in a file can be read with %s format. can you
please give me more detailed description on this. I mean ,the syntax
and where the file should be kept i.e in which directory ,in order to
access the file.

Thanks &Regards,
Raghu



sharp@cadence.com wrote:
raghu wrote:
I would like to give the binary output of text message as an input to
an algorithm which i have implemented using verilog.
can you please suggest me how to convert the text to binary.

You may need to describe more precisely what you are trying to do,
since an English description is not entirely clear.

You have some text. If it is in a file, you can read it with a %s
format into a reg. If it is already in a reg, then you can skip that
step. At this point, the reg contains binary bits that represent the
ASCII encoding of the text characters. If that is what you mean by
converting it to binary, then you don't have to do anything. That is
already how it is stored. Your Verilog algorithm can operate on the
contents of the reg.

If you want to do something else, then you need to describe it more
precisely.
 
raghu wrote:
Thanks a lot for your valuable response.
As you said that a text in a file can be read with %s format. can you
please give me more detailed description on this. I mean ,the syntax
and where the file should be kept i.e in which directory ,in order to
access the file.
Assuming that your simulator supports Verilog-2001 file I/O, you have a
lot of flexibility in this. You can keep the file anywhere you like,
since the filename argument to $fopen can be a full pathname including
directories. For relative paths, I believe $fopen uses the directory
you are running in as the current working directory, in most
implementations. So the simplest thing is to put the file in the
directory you are running in.

Then something like

integer fd, nread;
reg [NBYTES*8:1] message;

initial
begin
fd = $fopen("myfile", "r"); // open for reading
if (!fd)
$display("failed to open myfile");
else
begin
nread = $fscanf(fd, "%s", message);
if (nread != 1)
$display("failed to read message");
end
end

You could also use $fgets to read a line into the message buffer,
instead of $fscanf. Either way, the buffer will end up with the bits
representing the ASCII encoding of the string read in. If the string
is shorter than the buffer, the upper bits will all be zeroes.
 

Welcome to EDABoard.com

Sponsor

Back
Top