Advertisement
Guest User

Untitled

a guest
May 13th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4.  
  5.  
  6. namespace _07.OneSystemToAnyOther
  7. {
  8. class OneSystemToAnyOther
  9. {
  10.  
  11.  
  12. static Dictionary<char, int> decDigits = new Dictionary<char, int>()
  13. {
  14. {'0', 0 },
  15. {'1', 1 },
  16. {'2', 2 },
  17. {'3', 3 },
  18. {'4', 4 },
  19. {'5', 5 },
  20. {'6', 6 },
  21. {'7', 7 },
  22. {'8', 8 },
  23. {'9', 9 },
  24. {'A', 10 },
  25. {'B', 11 },
  26. {'C', 12 },
  27. {'D', 13 },
  28. {'E', 14 },
  29. {'F', 15 }
  30. };
  31. static ulong NToDec(string binary, int sBase)
  32. {
  33. ulong decValue = 0;
  34.  
  35. foreach (char digit in binary)
  36. {
  37. decValue = Convert.ToUInt64(decDigits[char.ToUpper(digit)]) + decValue * Convert.ToUInt64(sBase);
  38. }
  39.  
  40. return decValue;
  41. }
  42.  
  43.  
  44. static string baseDigits = "0123456789ABCDEF";
  45.  
  46. static string NToD(ulong decValue, int dBase)
  47. {
  48. string dValue = string.Empty;
  49.  
  50. do
  51. {
  52. int digit = Convert.ToInt32(decValue % Convert.ToUInt64(dBase));
  53. dValue = baseDigits[digit] + dValue;
  54. decValue /= Convert.ToUInt64(dBase);
  55. } while (decValue != 0);
  56.  
  57. return dValue;
  58. }
  59.  
  60. static void Main()
  61. {
  62. int s = int.Parse(Console.ReadLine());
  63. string N = Console.ReadLine();
  64. int d = int.Parse(Console.ReadLine());
  65.  
  66. Console.WriteLine(BigInteger.Parse(NToD(NToDec(N, s), d)));
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement