Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AnyNumeralSystem
- {
- static void Main()
- {
- Console.WriteLine("Enter base S to use:");
- int baseNumeralSystemS = int.Parse(Console.ReadLine());
- Console.WriteLine("\nEnter base D to convert:");
- int baseNumeralSystemD = int.Parse(Console.ReadLine());
- Console.WriteLine("\nEnter number:");
- string number = Console.ReadLine();
- int digit = 0;
- int sum = 0;
- int startIndex = number.Length - 1;
- for (int i = 0; i < number.Length; i++)
- {
- string part = number.Substring(startIndex, 1);
- digit = Convert.ToInt32(part) * (int)Math.Pow(baseNumeralSystemS, i);
- sum = sum + digit;
- startIndex--;
- }
- Console.WriteLine("\nShowing the result:");
- int count = 0;
- for (int i = 31; i >= 0; i--)
- {
- int exponent = (int)Math.Pow(baseNumeralSystemD, i);
- digit = sum / exponent;
- sum = sum % exponent;
- if (digit != 0)
- {
- count++;
- }
- if (count > 0)
- {
- Console.Write(digit);
- }
- }
- Console.WriteLine("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement