For positive integers, this is quite simple... you can start by finding the last digit using the modulo operator...
78332 % 10 --> 2
Once you have the last digit, you can drop the last digit from the number by dividing by 10 (integer division):
78332 / 10 -> 7833
You can repeat this process until all digits have been extracted (i.e. until the result of the division is 0).
For negative numbers, you just check if the number is negative at the beginning, and if so you simply remember that fact and turn it into positive by changing the sign. When you finish generating the text representation, you must add -
at the beginning if the number was originally negative.
A simple C version for the code would be something like this:
const char *myitoa(int x) {
static char buf[100];
int p = 98;
int neg = x < 0;
if (neg) x = -x;
do {
buf[--p] = '0' + x % 10;
x = x/10;
} while (x > 0);
if (neg) buf[--p] = '-';
return buf+p;
}
Note that this is a very simple implementation, not handling all cases (for example, there is a problem with the largest possible negative number, it doesn't work in a multi-threaded environment, and it overwrites the previous result every time you call it, so it's dangerous to call it in an interrupt handler, for example).