Hello
basically i'm trying to convert two chars received from an XBee.
so i have char[0] and char[1]
say this gives me 2 and 3.
I need to combine them into an int which makes 23.
any suggestions?
Thanks in advance
Hello
basically i'm trying to convert two chars received from an XBee.
so i have char[0] and char[1]
say this gives me 2 and 3.
I need to combine them into an int which makes 23.
any suggestions?
Thanks in advance
Assuming that your char array holds the ASCII values of the 2 digits :
int theInt = ( 10 * (char[0] - '0' ) ) + char[1] - '0';
You could use:
int number = 10*(char[0] - '0') + char[1] - '0';
(given that char[0] == '2', and not 2 (uint8_t))
Or if the array is null-terminated (i.e. char[2] == '\0'):
int number = atoi(char);
Pieter
Thanks for the reply's!
code is working now