ASCII - Convert DEC to Character

Hello guys,

I spent some time trying to find a library file or some function that would easily convert an ASCII DEC to a character. I found a lookup chart, but, trying to create a function out of that entire chart would take ages, I figured someone may have already made a solution to this?

I'm using an FTDI chip to send data via serial to my Arduino from C#, it's sending each byte as an ASCII DEC which I wanted to convert to character in the Arduino program.

Neither "ASCII DEC" nor "Character" really make any sense. Are you saying that you want to take an ASCII-encoded decimal number, like '4', and turn it into an int?

If you're starting with a char (one letter; it's what's returned by Serial.read()), the simplest way is to subtract '0'. Since the ASCII codes for numbers are in order, subtracting '0' means that '0' will become 0, '1' will become 1, '2' will become 2, and so on.

If you're starting from a NULL-terminated string, you can use atoi (google it)

I wanted to know if there is an easy way (library/pre-made function done by someone) that I can pass to convert characters like "A" into an ASCII-encoded decimal number.

I think I'm also confused as to what exactly you want to do.

char myChar = 'A';

Stores the ASCII value of A in myChar, as illustrated by this sketch.

char myChar = 'A';

void setup()
{
  Serial.begin(57600);
  Serial.print("Character: ");
  Serial.println(myChar);
  Serial.print("Decimal Value: ");
  Serial.println(myChar, DEC);
}

void loop()
{
}

A quick google search of the term ascii dec returns rubbish. It's either converting from ascii to dec or the other way around. Nothing is called ascii dec. You have to provide examples. Since C has a long history, including times when processing text was quite important, I doubt there is something that C simply fails to provide, as long as you can name exactly what it is that you want.

Thank you dxw00d, that was exactly what I needed. Sorry guys for not explaining it properly, I wasn’t sure how to myself. :smiley: