Last active
December 17, 2015 16:49
-
-
Save rossmurray/5641391 to your computer and use it in GitHub Desktop.
Converts a number to an arbitrary radix (base), with configurable character set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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