in lib/nxp/utilities/fsl_str.c [514:623]
static int32_t ConvertRadixNumToString(char *numstr, void *nump, int32_t neg, int32_t radix, bool use_caps)
{
#if PRINTF_ADVANCED_ENABLE
int64_t a;
int64_t b;
int64_t c;
uint64_t ua;
uint64_t ub;
uint64_t uc;
uint64_t uc_param;
#else
int32_t a;
int32_t b;
int32_t c;
uint32_t ua;
uint32_t ub;
uint32_t uc;
uint32_t uc_param;
#endif /* PRINTF_ADVANCED_ENABLE */
int32_t nlen;
char *nstrp;
nlen = 0;
nstrp = numstr;
*nstrp++ = '\0';
if (0 != neg)
{
#if PRINTF_ADVANCED_ENABLE
a = *(int64_t *)nump;
#else
a = *(int32_t *)nump;
#endif /* PRINTF_ADVANCED_ENABLE */
if (a == 0)
{
*nstrp = '0';
++nlen;
return nlen;
}
while (a != 0)
{
#if PRINTF_ADVANCED_ENABLE
b = (int64_t)a / (int64_t)radix;
c = (int64_t)a - ((int64_t)b * (int64_t)radix);
if (c < 0)
{
uc = (uint64_t)c;
uc_param = ~uc;
c = (int64_t)uc_param + 1 + (int64_t)'0';
}
#else
b = a / radix;
c = a - (b * radix);
if (c < 0)
{
uc = (uint32_t)c;
uc_param = ~uc;
c = (int32_t)uc_param + 1 + (int32_t)'0';
}
#endif /* PRINTF_ADVANCED_ENABLE */
else
{
c = c + (int32_t)'0';
}
a = b;
*nstrp++ = (char)c;
++nlen;
}
}
else
{
#if PRINTF_ADVANCED_ENABLE
ua = *(uint64_t *)nump;
#else
ua = *(uint32_t *)nump;
#endif /* PRINTF_ADVANCED_ENABLE */
if (ua == 0U)
{
*nstrp = '0';
++nlen;
return nlen;
}
while (ua != 0U)
{
#if PRINTF_ADVANCED_ENABLE
ub = (uint64_t)ua / (uint64_t)radix;
uc = (uint64_t)ua - ((uint64_t)ub * (uint64_t)radix);
#else
ub = ua / (uint32_t)radix;
uc = ua - (ub * (uint32_t)radix);
#endif /* PRINTF_ADVANCED_ENABLE */
if (uc < 10U)
{
uc = uc + (uint32_t)'0';
}
else
{
uc = uc - 10U + (uint32_t)(use_caps ? 'A' : 'a');
}
ua = ub;
*nstrp++ = (char)uc;
++nlen;
}
}
return nlen;
}