extern const char digit1[101] = "00000000001111111111222222222233333333334444444444" "55555555556666666666777777777788888888889999999999"; extern const char digit2[101] = "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789"; // 把无符号整数转换为字符串,返回字符串范围是[buffer + begin, buffer + bufLen] size_t uintToBuffer(char* const buffer, size_t bufLen, uint64_t v) { extern const char digit1[101], digit2[101]; for (;;) { if (v < 100) { if (v < 10) { buffer[--bufLen] = static_cast<char>(v + '0'); } else { size_t r = static_cast<size_t>(v); bufLen -= 2; buffer[bufLen] = digit1[r]; buffer[bufLen + 1] = digit2[r]; } break; } uint64_t t = v; v /= 100; size_t r = static_cast<size_t>(t - v * 100); bufLen -= 2; buffer[bufLen] = digit1[r]; buffer[bufLen + 1] = digit2[r]; } return bufLen; }
http://wm.ite.pl/articles/sse-itoa.html