Advertisement
LardaX

Convert-from-Base-N-to-Base-10

Oct 18th, 2016
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Convert_from_Base_N_to_Base_10
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] input = Console.ReadLine().Trim().Split();
  15.             int baseNNum = int.Parse(input[0]);
  16.             char[] baseTenNum = input[1].ToCharArray();
  17.  
  18.             BigInteger result = new BigInteger(0);
  19.  
  20.             for (int i = 0; i < baseTenNum.Length; i++)
  21.             {
  22.                 int currentNum = (int)Char.GetNumericValue(baseTenNum[i]);
  23.                 result += currentNum * BigInteger.Pow(baseNNum, baseTenNum.Length - i - 1);
  24.             }
  25.  
  26.             Console.WriteLine(result);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement