Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Base26Converter
- {
- private const string CharList = "abcdefghijklmnopqrstuvwxyz";
- public static String Encode(long input)
- {
- if (input < 0) throw new ArgumentOutOfRangeException("input", input, "input cannot be negative");
- char[] clistarr = CharList.ToCharArray();
- var result = new Stack<char>();
- while (input != 0)
- {
- result.Push(clistarr[input % 26]);
- input /= 26;
- }
- return new string(result.ToArray());
- }
- public static Int64 Decode(string input)
- {
- var reversed = input.ToLower().Reverse();
- long result = 0;
- int pos = 0;
- foreach (char c in reversed)
- {
- result += CharList.IndexOf(c) * (long)Math.Pow(26, pos);
- pos++;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement