Convert integer to decimal string I have a need to do some conversions in a loop to display the results using C++98 on Linux, which doesn't have any itoa() to complement atoi(). I opted for this instead of snprintf(). This is for an embedded device and the conversions will be done in a few loops, so speed is important.

It's based on some code I found on GitHub.  I modified it to write to a user-supplied buffer, so that it's reentrant.

Please let me know if anyone has a better method for small numeric conversions to ascii using base-10 only, or any recommended changes. Thanks. 

/*
  Modified from:
  https://gist.github.com/madex/c5cd5c6a23965a845d6e

  This only works for up to 9 digits and only converts to base 10 ascii,
  but no division is used and this method is very fast.
*/

void itoaBase10(int32_t num, char *string, int lengthOfString)
{
    if (!string || num &gt; 9999999999)
    return;
    memset(string, 0, lengthOfString);
    static uint32_t subtractors[10] =
     { 1000000000, 100000000, 10000000, 1000000, 100000, 10000,
       1000, 100, 10, 1 };
    char n, *str = string, sign = num &lt; 0 ? '-' : ' ';
    uint32_t *sub = subtractors;
    uint32_t u = num &lt; 0 ? (uint32_t)-num : (uint32_t)num;
    uint8_t  i = 10;
    while (i &gt; 1 &amp;&amp; u &lt; *sub)
    {
        i--;
        sub++;
    }
    str++;
    *(str - 1) = sign;
    while (i--)
    {
        n = '0';
        while (u &gt;= *sub)
        {
            u -= *sub;
            n++;
        }
        *str++ = n;
        sub++;
    }
}
Since the function may bail out without computing the result, it must signal the caller that something got wrong. Consider returning an error code.
Since you are dealing with negative numbers, testing for num &gt; 9999999999 is not sufficient.
Along the same line, -num may overflow. 
The lines

    str++;
    *(str - 1) = sign;


are a long way to say

    *str++ = sign;


That said, you seem to force a sign (a whitespace) into the output even for positives. Strictly speaking, it is not an itoa compatible behavior.
memset seems superfluous. *str = 0; after the conversion is done suffices.
I don't think that the benefits of a subtraction loop vs division/modulo are measurable. Did you profile?
The only reason to prefer itoa to sprintf is that the former supports arbitrary conversion bases. It you only need decimal conversion, I strongly recommend to stick with the latter.