Feb 12, 2002 #1 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)
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)
Feb 12, 2002 #2 Zyrenthian Programmer Mar 30, 2001 1,440 US 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 Upvote 0 Downvote
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
Feb 12, 2002 #3 Themuppeteer Programmer Apr 4, 2001 449 BE 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... Upvote 0 Downvote
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...
Feb 12, 2002 #4 Themuppeteer Programmer Apr 4, 2001 449 BE 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... Upvote 0 Downvote
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...