fork(13) download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. Console.WriteLine(BaseConvert("8418CFEE73FA22E6AB0760C73A496497C6C347DA88A9F63B95FE1E1D6A350AA1D7D3A9EE870795AECC3C109AA8B4A78C", 16, 36));
  9. }
  10. public static string BaseConvert(string number, int fromBase, int toBase)
  11. {
  12. var digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  13. var length = number.Length;
  14. var result = string.Empty;
  15.  
  16. var nibbles = number.Select(c => digits.IndexOf(c)).ToList();
  17. int newlen;
  18. do {
  19. var value = 0;
  20. newlen = 0;
  21.  
  22. for (var i = 0; i < length; ++i) {
  23. value = value * fromBase + nibbles[i];
  24. if (value >= toBase) {
  25. if (newlen == nibbles.Count) {
  26. nibbles.Add(0);
  27. }
  28. nibbles[newlen++] = value / toBase;
  29. value %= toBase;
  30. }
  31. else if (newlen > 0) {
  32. if (newlen == nibbles.Count) {
  33. nibbles.Add(0);
  34. }
  35. nibbles[newlen++] = 0;
  36. }
  37. }
  38. length = newlen;
  39. result = digits[value] + result; //
  40. }
  41. while (newlen != 0);
  42.  
  43. return result;
  44. }
  45. }
Success #stdin #stdout 0.02s 33888KB
stdin
Standard input is empty
stdout
1DWCLWKQZK16WMKIIEYVLLXA9E4OQ64P80KDOH4ALCYRCYCTKRUHQRXTM6HLDEV78E6APXQV1JG