Last active
March 14, 2016 10:56
-
-
Save herman1vdb/8c0677120f67e5f4a8a6 to your computer and use it in GitHub Desktop.
Decimal To Tetrasexagesimal and back extension methods C# (logic from http://stackoverflow.com/a/4964352/3325104)
This file contains hidden or 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 static class extensions | |
{ | |
public static char[] baselist = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-".ToCharArray(); | |
public static StringBuilder toNumericBase64(this int number) | |
{ | |
StringBuilder res = new StringBuilder(); | |
var r = number % baselist.Length; | |
res.Append(baselist[r]); | |
int q = (int)Math.Floor((decimal)(number / baselist.Length)); | |
while (q != 0) { | |
r = q % baselist.Length; | |
q = (int)Math.Floor((decimal)(q / baselist.Length)); | |
res.Append(baselist[r]); | |
} | |
return res; | |
} | |
public static string toNumericBase10(this string number) | |
{ | |
var numbers = number.Reverse().ToArray(); | |
int res = Array.IndexOf(baselist, numbers[0]); | |
for (int i = 1;i <number.Length;i++) { | |
res = baselist.Length * res + Array.IndexOf(baselist, numbers[i]); | |
} | |
return res.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment