#include #include bool try_sntoi(const char *s, uint32_t n, uint32_t *out) { uint32_t calc = 0; for (uint32_t i = 0; i < n; ++i) { if ((s[i] < '0') || (s[i] > '9')) return false; calc = calc * 10 + s[i] - '0'; } *out = calc; return true; } void itosz(uint32_t i, char *out) { if (!i) { *(uint16_t *)out = (uint16_t)'0'; return; } bool zero = false; for (uint32_t m = 1000000000; m; m /= 10) { uint8_t d = (i / m) % 10; if (zero) *(out++) = d + '0'; else if (d) { zero = true; *(out++) = d + '0'; } } *out = '\0'; }