Help converting from char to int

I'm trying to convert the char '1' to the integer 1 and having trouble. The following code:

void setup() {
  Serial.begin(115200);
}

void loop() {
  char a = '1';
  int b = (int)a;
  Serial.println(a);
  Serial.println(b);
  Serial.println("---");
  delay(1000);
}

Produces:
1
49

Any tips on converting the char '1' to the integer 1?

Thanks for any help.

  Serial.begin(115200);
}

void loop() {
  char a = '1';
  int b = a - '0';

The easiest way to convert a single digit from ascii is to just subtract 48 (the value of '0')

Thank you!

But don't forget bounds checking - what do you do if it is not 0 to 9?

In your other thread you are trying to convert from an int to a char. I wonder, do you actually need to convert it either way ?

UKHeliBob:
In your other thread you are trying to convert from an int to a char.

Whatever that means! :astonished: