|
-
Feb 11th, 2003, 07:40 PM
#1
Thread Starter
Junior Member
[RESOLVED] int to ASCII..
How would I go about converting an integer to it's equivalent ASCII value?
Last edited by xuralarux; Feb 13th, 2003 at 08:24 PM.
Before you say anything about this post...you're welcome.
"I love animals... I eat them and wear their skin."
"Why do those who know the least, know it the loudest?"
"You live and learn. Or you don't live long."
Which Colossal Death Robot Are You?
-
Feb 11th, 2003, 07:59 PM
#2
Hyperactive Member
-
Feb 11th, 2003, 08:02 PM
#3
Hyperactive Member
If you just want to convert a single digit (0-9), do this
char character=(char)(digit+48);
-
Feb 11th, 2003, 08:32 PM
#4
Thread Starter
Junior Member
Does that return the string representation of a number (ie "65"), or for a value like 65 return the equivalent ASCII character, "A"?
-
Feb 11th, 2003, 09:48 PM
#5
Frenzied Member
All characters are represented as numbers in a computer -
char can be treated as a number (unsigned: 1-255) (signed -127 -127)or whatever the ASCII designation for the char is. Internally it is still a number.
Code:
char s;
for(s=65;s<91;s++) printf(" %c \n",s);
And you can convert any integer that is <255 to char. Many character functions like getc() actually use integers. Not char.
char and int are interchangeable for a lot of functions.
-
Feb 11th, 2003, 09:56 PM
#6
Hyperactive Member
Originally posted by xuralarux
Does that return the string representation of a number (ie "65"), or for a value like 65 return the equivalent ASCII character, "A"?
I think someone else had shown this piece of code here before.
cout<<(int)('A')<<endl;//65
cout<<(char)(65)<<endl;//'A' character
-
Feb 12th, 2003, 07:32 PM
#7
[edit]Forget what I said here. I was tired.[/edit]
For a long number, it's sprintf (_itoa is an MS extension).
Last edited by CornedBee; Feb 13th, 2003 at 03:38 AM.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 12th, 2003, 08:25 PM
#8
Thread Starter
Junior Member
-
Feb 13th, 2003, 01:29 AM
#9
Hyperactive Member
Originally posted by CornedBee
BTW it's not + 48 but either + 0x48 or + 65 or (best) + 'A'.
For a long number, it's sprintf (_itoa is an MS extension).
BTW it's not + 48 but either + 0x41 or + 65 or (best) + 'A'.
Anyway I'm really referring to 48. 48 is the ascii no for '0' since the thread title is 'int to ASCII'.
-
Feb 13th, 2003, 03:37 AM
#10
Oh yeah, stupid me.
It was 2 AM...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 13th, 2003, 08:08 PM
#11
Thread Starter
Junior Member
Thanks for the help all, got the program done.
Before you say anything about this post...you're welcome.
"I love animals... I eat them and wear their skin."
"Why do those who know the least, know it the loudest?"
"You live and learn. Or you don't live long."
Which Colossal Death Robot Are You?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|