Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bases5
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Console.WriteLine(ToBase(16,(int)fromBase(2,10111))); } public static double ToBase(double baseNum, int num) { int maxPow = 0; List<double> order = new List<double>(); List<double> orderReverse = new List<double>(); double total = 0; double remander; //Find Highest Power Needed for (int i = 0; i < 20; i++) { if (num < Math.Pow(baseNum,i)) { maxPow = i; break; } } remander = num; //Convert to Digits for (double i = maxPow; i >= 0; i--) { order.Add(Math.Floor(remander / Math.Pow(baseNum, i))); remander = remander % Math.Pow(baseNum, i); } //print for (int i = order.Count()-1; i > 0; i--) { //Console.WriteLine(order[i]); orderReverse.Add(order[i]); } for (int i = 0; i < orderReverse.Count(); i++) { total += orderReverse[i]*Math.Pow(10,i); } return total; } public static double fromBase(double baseNum, int num) { int maxPox = 0; List<double> listOfInts = new List<double>(); double output = 0; while(num > 0) { listOfInts.Add(num % 10); num = num / 10; } for(int i = 0; i < listOfInts.Count(); i++) { output += listOfInts[i]*Math.Pow(baseNum,i); } return output; } } }
run
|
edit
|
history
|
help
0
Numbers separated by space
30272 Program Ex5 if_else2_odd_even
Hzzz
2
ggg
png
Daily Coding Problem: Problem #2
Reverse String and Binary Search of floating point values
655+99
Prime number