you mean you want boo to be the ASCII representation of your int ?
why would that fit in only one char ? an int can be large, event if it's only one byte it can range from 0 to 255
if you know that your number kaboom is actually a single digit (0 to 9) then you can get the ASCII representation by adding the ASCII value of '0'.
int kaboom = 2;
char boo = '0' + kaboom:
if (boo == 50 ) {...} // same as if (boo == '2') {....}
but I don't see the benefit in doing so, just compare kaboom with the number 2
J-M-L:
you mean you want boo to be the ASCII representation of your int ?
why would that fit in only one char ? an int can be large, event if it's only one byte it can range from 0 to 255
if you know that your number kaboom is actually a single digit (0 to 9) then you can get the ASCII representation by adding the ASCII value of '0'.
int kaboom = 2;
char boo = '0' + kaboom:
if (boo == 50 ) {...} // same as if (boo == '2') {....}
but I don't see the benefit in doing so, just compare kaboom with the number 2 :)
J-M-L:
you mean you want boo to be the ASCII representation of your int ?
why would that fit in only one char ? an int can be large, event if it's only one byte it can range from 0 to 255
if you know that your number kaboom is actually a single digit (0 to 9) then you can get the ASCII representation by adding the ASCII value of '0'.
int kaboom = 2;
char boo = '0' + kaboom:
if (boo == 50 ) {...} // same as if (boo == '2') {....}
but I don't see the benefit in doing so, just compare kaboom with the number 2 :)
Thank you for your answer, I begin to understand and for the anwer on your question: (what's the benefit?) well it's just for comparing the input of my bluetooth module since you can only get the input char by char. What's the best way to compare your input of the bluetooth module with an int according to you?
I would suggest to study Serial Input Basics to get started and understand how to deal with your Serial input.
if you only receive commands that fit on 1 byte, then it's easier and you can compare whatever you get (you need to know what comes in of course, ASCII or binary) and to test is just an
So the symbol '0' is coded 48, the symbol '1' is coded 49 etc...
when you do char c = '1'; the compiler stores the ASCII code (because you rightly used single quotes around the symbol to denote a character) in c, so the value of c is 49.
to get the integer representation, you subtract 48 which is the ASCII code of '0' (as symbols for 0 to 9 are one after another in the table)
char c = '1'; // c holds the value 49
int v = c - '0'; // v holds de value 1