Skip to content

Instantly share code, notes, and snippets.

@Delamare2112
Last active February 13, 2017 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Delamare2112/9ec36b7f3e935e172393c5ea63c133f8 to your computer and use it in GitHub Desktop.
Save Delamare2112/9ec36b7f3e935e172393c5ea63c133f8 to your computer and use it in GitHub Desktop.
std::string itoawb(size_t val, size_t base)
{
if(val == 0)
return "0";
size_t buffSize = (size_t)(log2(val) + 1);
std::string ret(buffSize, 0);
buffSize *= 1.25;
buffSize++;
size_t i = buffSize-1;
for(;val && i; --i, val /= base)
{
ret[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[val % base];
}
int j = 0;
i++;
for(; i < buffSize; i++, j++)
ret[j] = ret[i];
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment