My Base36 conversion extension method

Posted by Mikael Östberg | Filed under

I made a little method for conversion from decimal to base36. It can be tweaked into converting to any base beneath 36, however.

public static string ToBase36(this int num) {
    char[] chars = "0123456789abcdefghijklmnopqrstuvwxyz".ToCharArray();
    string ret = string.Empty;
    do {
        ret = chars[Math.Abs(num) % chars.Length] + ret;
    } while ((num = num / chars.Length) > 0);

    return ret;
}

Comments

Add comment




biuquote
  • Comment
  • Preview
Loading