Skip to content

Instantly share code, notes, and snippets.

@rossmurray
Last active December 17, 2015 16:49
Show Gist options
  • Save rossmurray/5641391 to your computer and use it in GitHub Desktop.
Save rossmurray/5641391 to your computer and use it in GitHub Desktop.
Converts a number to an arbitrary radix (base), with configurable character set.
public string ConvertToBase(uint value, char[] characterSet)
{
var radix = (uint)characterSet.Length;
var result = new List<char>();
do
{
var remainder = value % radix;
value = value / radix;
result.Add(characterSet[remainder]);
} while(value > 0);
result.Reverse();
return new string(result.ToArray());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment