Advertisement
Mitax

ConvertFromBase_NtoBase_10

Jun 12th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. namespace _05.ConvertFromBase_NtoBase_10
  2. {
  3. using System;
  4. using System.Numerics;
  5. public class FromBase
  6. {
  7. public static void Main()
  8. {
  9. string[] line = Console.ReadLine().Trim().Split();
  10. int baseN = int.Parse(line[0]);
  11. char[] number = line[1].ToCharArray();
  12. BigInteger result = new BigInteger(0);
  13. for (int i = number.Length - 1, n = 0; i >= 0; i--, n++)
  14. {
  15. BigInteger num = new BigInteger(char.GetNumericValue(number[n]));
  16. BigInteger forSum = BigInteger.Multiply(num, BigInteger.Pow(new BigInteger(baseN), i));
  17. result += forSum;
  18. }
  19. Console.WriteLine(result.ToString());
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement