ASCII conversion

R

raghu

Guest
/ / C program

char ch;
scanf("%c",ch);
printf("%d",ch);

output gives us ASCII of character stored in ch..

Likewise is it possible in verilog to do same thing i.e taking the
input char(not as binary) and printing the ASCII value of the character
given.

Hoping for a positive response.

Thanks a lot.

Regards,
Raghu
 
"raghu" <raghujindia@gmail.com> a écrit dans le message de news:
1160088049.392491.105540@k70g2000cwa.googlegroups.com...
/ / C program

char ch;
scanf("%c",ch);
printf("%d",ch);

output gives us ASCII of character stored in ch..

Likewise is it possible in verilog to do same thing i.e taking the
input char(not as binary) and printing the ASCII value of the character
given.

Hoping for a positive response.

Thanks a lot.

Regards,
Raghu
Hi Raghu,

I think this will do what you want:

integer file,ch;
$fscanf(file,"%c",ch);
$display("%d",ch);

I don't know any way to read from the keyboard as your C example let think
you want to do.
To write to a file instead of the screen, do a $fdisplay.

Serge
 
Hi Serge,

Thanks a lot for your valuable response.
I could not understand the statement $fscanf(file,"%c",ch); what is
file here?
can explain in detail.

Thanks a lot.

Regards,
Raghu
 
It might be helpful to look in the help resources available to you from your
simulator to understand these functions. Why ask when you can read the
manual?


"raghu" <raghujindia@gmail.com> wrote in message
news:1160159544.016152.105620@k70g2000cwa.googlegroups.com...
Hi Serge,

Thanks a lot for your valuable response.
I could not understand the statement $fscanf(file,"%c",ch); what is
file here?
can explain in detail.

Thanks a lot.

Regards,
Raghu
 
Serge Bédikian wrote:
I don't know any way to read from the keyboard as your C example let think
you want to do.
There is a pre-defined value for a file descriptor that represents
STDIN. However, implementations may differ in support for this, and in
where it actually reads from. For example, if you are using a GUI with
your simulator, the text input to the GUI window is different from the
standard input of the simulator.
 

Welcome to EDABoard.com

Sponsor

Back
Top