Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,644 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,097 people online right now. Registration is fast and FREE... Join Now!




c++ Use of ASCII codes

2 Pages V  1 2 >  
Reply to this topicStart new topic

c++ Use of ASCII codes

annupriya
post 6 Aug, 2008 - 07:15 AM
Post #1


New D.I.C Head

*
Joined: 6 Aug, 2008
Posts: 1

how i can use asci code in c++?
User is offlineProfile CardPM

Go to the top of the page

red_4900
post 6 Aug, 2008 - 07:19 AM
Post #2


Code Dreamers

****
Joined: 22 Feb, 2008
Posts: 792



Thanked 10 times
My Contributions


can you use Google?
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 6 Aug, 2008 - 07:39 AM
Post #3


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,858



Thanked 47 times

Dream Kudos: 550
My Contributions


Well how or what you do with ASCII code is up to you. Its just a convention. Generally speaking characters (char) are sort of like photons in physics. They can be numbers, or they can be characters.
CODE
    char c = 0x41;
    printf ("As a character: %c\n", c);
    printf ("As a as a number: %d\n", c);
    printf ("As a hex: 0x%X\n", c);


This is because all characters are are numbers...
CODE
    int c = 0x41;
    printf ("As a character: %c\n", c);
    printf ("As a as a number: %d\n", c);
    printf ("As a hex: 0x%X\n", c);


User is offlineProfile CardPM

Go to the top of the page

chendy1985
post 6 Aug, 2008 - 07:54 AM
Post #4


New D.I.C Head

*
Joined: 6 Aug, 2008
Posts: 7



Thanked 1 times
My Contributions


QUOTE(annupriya @ 6 Aug, 2008 - 08:15 AM) *

how i can use asci code in c++?


do u mean:
CODE

#include <iostream>

using namespace std;

int main()
{
    char a = 'a';
    int b = (int)a;
    cout << b << endl;
    return 0;
}


output : 97

this means 97 is the ascii code for a
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 6 Aug, 2008 - 08:20 AM
Post #5


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,440



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


If you're using C++ you could do this, too:
cpp

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
char a = 'a';
int b = static_cast <int> (a);
cout << b << endl;
cin.get ();
return EXIT_SUCCESS;
}
Which will output 97 as well smile.gif
User is online!Profile CardPM

Go to the top of the page

Codegamer
post 6 Aug, 2008 - 09:54 AM
Post #6


D.I.C Head

**
Joined: 4 May, 2008
Posts: 127


My Contributions


QUOTE(annupriya @ 6 Aug, 2008 - 08:15 AM) *

how i can use asci code in c++?



CODE

#include <iostream>

using namespace std;

int main ()
{

cout << "                              ,.=,,==. ,,_ " << endl
<< "                    _ ,====, _    |I|`` ||  `|I `| " << endl
<< "                   |`I|    || `==,|``   whatsthat.gif   ``  | " << endl
<< "                   | ``    ^^    ||_,===TT`==,,_ | " << endl
<< "                   |,==Y``Y==,,__| \L=_-`'   +J/` " << endl
<< "                    \|=_  ' -=#J/..-|=_-     =| " << endl
<< "                     |=_   -;-='`. .|=_-     =|----T--, " << endl
<< "                     |=/\  -|=_-. . |=_-/^\  =||-|-|::|____ " << endl
<< "                     |=||  -|=_-. . |=_-| |  =|-|-||::\____ " << endl
<< "                     |=LJ  -|=_-. . |=_-|_|  =||-|-|::::::: " << endl
<< "                     |=_   -|=_-_.  |=_-     =|-|-||:::::: " << endl
<< "                     |=_   -|=//^\. |=_-     =||-|-|::::::: " << endl
<< "                 ,   |/&_,_-|=||  | |=_-     =|-|-||::::::: " << endl
<< "             ,--``8%,/    ',%||  | |=_-     =||-|-|%:::::: " << endl
<< "         ,---`_,888`  ,.'''''`-.,|,|/!,--,.&\|&\-,|?::::: " << endl
<< "         |;:;K`__,...;=\_____,=``           %%%&     %#,--- " << endl
<< "         |;::::::::::::|       `'.________+-------\   `` " << endl
<< "   |    /8M%;:::;;:::::|                  |        `------- " << endl
<< "   |   |`   88`V  /&8%\|_______,__,,      |                " << endl
<< "   |   /,  %8,  ,/&888% &,       ,  `-----`,--..../|--,,,,_ " << endl
<< "  / \/88%  88%  8888%88% &,       \,     `\      /     &,, " << endl
<< "  |,M8,  , `8%   ,,8% `8, `         , \,        &\     ,?# " << endl
<< " /8888%  888`    ```    `            `  `               ```  " << endl;

return 0;
}

User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 6 Aug, 2008 - 10:12 AM
Post #7


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,440



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


Neat icon_up.gif

How long did it take you to do that?

By the way, that's called ASCII art~ it's not so much a major use of ASCII as just drawing pretty pictures in the console.

I believe WolfCoder has a snippet to turn a jpg into ASCII art, but I never tested it.
User is online!Profile CardPM

Go to the top of the page

Codegamer
post 6 Aug, 2008 - 10:18 AM
Post #8


D.I.C Head

**
Joined: 4 May, 2008
Posts: 127


My Contributions


QUOTE(gabehabe @ 6 Aug, 2008 - 11:12 AM) *

Neat icon_up.gif

How long did it take you to do that?

By the way, that's called ASCII art~ it's not so much a major use of ASCII as just drawing pretty pictures in the console.

I believe WolfCoder has a snippet to turn a jpg into ASCII art, but I never tested it.


Haha funny *tears* I never though that you ever gonna talk to me anymore... I don't know but maybe bacause I gived you msn to on of my "callled" friends?
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 6 Aug, 2008 - 10:53 AM
Post #9


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,440



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


...You never answered my question sleep.gif
User is online!Profile CardPM

Go to the top of the page

Codegamer
post 6 Aug, 2008 - 10:56 AM
Post #10


D.I.C Head

**
Joined: 4 May, 2008
Posts: 127


My Contributions


QUOTE(gabehabe @ 6 Aug, 2008 - 11:53 AM) *

...You never answered my question sleep.gif


Yes I know that it's ASCII art... and I took it from another site but I've some own too. (that's better)
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 6 Aug, 2008 - 11:28 AM
Post #11


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,440



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


THIEF!


tongue.gif
User is online!Profile CardPM

Go to the top of the page

Codegamer
post 6 Aug, 2008 - 11:30 AM
Post #12


D.I.C Head

**
Joined: 4 May, 2008
Posts: 127


My Contributions


QUOTE(gabehabe @ 6 Aug, 2008 - 12:28 PM) *

THIEF!


tongue.gif


Do you think people put something that you have to pay for but you can copy it as a text? (I don't think so...)
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 11/23/08 04:42AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month