Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ascii to integer

Status
Not open for further replies.

sjmojeck

Technical User
Sep 6, 2001
24
US
How do you convert an ascii character to its integer value
(example the ascii character is 5 I need the integer value to be 5)
 
one way is to

char x = 5;
int i = (int)x;


another is atoi but that works with strings, if this is what you mean

char val[] = "123";
int i = atoi(val);

Matt
 
You should add a number to your char.
You look in your ascii table and search for the ascii value of '0' wich is:48
So:

int i=5;
char t=i;
t+=48;
//now t contains the char 5

Hope this is what you mean.




Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Oeps,sorry you want char to int.
Well thats just the opposite;
char t='5';
int i=t-48;
//i is now 5
:) Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top