Link to home
Start Free TrialLog in
Avatar of manishk1111
manishk1111

asked on

Converting alphabet to ascii

How to convert an alphabet to ascii equivalent in C?
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Your question, as it stands, doesn't really make a lot of sense. Can you elaborate please so that we may assist you properly?
char a = 'a';
ASKER CERTIFIED SOLUTION
Avatar of Farzad Akbarnejad
Farzad Akbarnejad
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ashley2009
ashley2009

The ASCII table is:

http://www.asciitable.com/

I think that this article at Bytes might help you. I cannot guarantee as I forgot c and c++:


http://bytes.com/topic/c/answers/769137-how-convert-alphabet-numbers

Another article on c++:
http://www.dreamincode.net/code/snippet566.htm
Hi,

     A character have its own ASCII-value, you can see it when you represent as integer,
refer ascii table as well,
http://www.asciitable.com/
#include<stdio.h>

int main()
{

  char alpha,c;
  unsigned short asciiValue = 0;
  while(1)
  {
    printf("Enter an alphabet :");
    scanf("%c",alpha);
    asciiValue = (unsigned short) alpha; //Cast required (converts one type to another)
    printf("\n Ascii value of %c is %d \n",alpha, asciiValue);
    /* Revrse what you have done */
    c = (char ) asciiValue; // Cast required
    printf("\n The number %d represents the %c alpha in ascii table \n", asciiValue, c);
    
  }
  return 0;
}

Open in new window

   scanf("%c",&alpha);
    asciiValue = (unsigned short) alpha; //Cast not required
    printf("\n Ascii value of %c is %d \n",alpha, asciiValue);
    /* Revrse what you have done */
    c = (char ) asciiValue; // Cast not required
>>How to convert an alphabet to ascii equivalent in C?

Please don't ask C questions in the Java zone - it just wastes people's time
This gives the decimal equilivant:

#include <iostream>
using namespace std;
int AsciiValue = 0;

int main () {
while ( AsciiValue <= 266) {
cout <<AsciiValue<<" : "<<char(AsciiValue)<<endl;
AsciiValue += 1;
}
cin.get();
}

---

And this will give the hex equilivant:

#include <iostream>
using namespace std;
int AsciiValue = 0;

int main () {
while ( AsciiValue <= 266) {
cout<<"0x";
printf("%X", AsciiValue);
cout <<" : "<<char(AsciiValue)<<endl;
AsciiValue += 1;
}
cin.get();
}
"while ( AsciiValue <= 266) {"

ASCII ranges from 0 - 255. The above statement is incorrect.
ASCII ranges from 0 - 127
ISO-8859 ranges from 0 - 255 (which may have been what the asker meant)
and of course all of the answers are wrong if the host environment is EBCDIC