# Thread: itoa - going back to char.

1. ## itoa - going back to char.

OK, I was expecting to see 3 integers converted to characters and then the characters trunckated together back into an integer (like this 12 34 56 to 123456) How far off am I here?

char string2[8] = {0,0,0,0,0,0,0,0};
char gbf[2] = {0,0};
char gbi[2] = {0,0};
char gbs[2] = {0,0};

feet = abs(workc);
inch = abs((workc-feet)*12);
six = abs((((workc-feet)*12)-inch)*16);

itoa(feet,gbf,2);
itoa(inch,gbi,2);
itoa(six,gbs,2);
sprintf(string2,"%2.d%2.d%2.d", &gbf, &gbi, &gbs);

m_feet2 = atoi(string2);

2. The last argument in itoa is the radix of the outputted number. Using 10 will give you a decimal number (the 'normal' kind). 2, like you've typed, will give you a binary number (1010101110101) which may not be what you expect...

Also, remember that strings contain a NULL terminator so if you have 2 characters i it, it must be 3 characters wide.

Oh, and the easiest way would be to add the integers first, then transform them into a string. Integer addition is a lot easier to perform than string concatenation.
Code:
```int Total = (feet * 10000) + (inch * 100) + six
itoa(Total, Buffer, 10);```
Assuming they are max 2 digits long each.