Dec2Any

                               public static void Main()

                               {

                                               try

                                               {

                                                               Console.Write("Enter
the number base: "
);

                                                               string baseData = Console.ReadLine();

                                                               int numberBase = int.Parse(baseData,
NumberStyles.Integer);

                                                               Console.Write("Enter
the number: "
);

                                                               string data = Console.ReadLine();

                                                               int number = int.Parse(data,
NumberStyles.Integer);

                                                               Console.WriteLine(GetDec2Any(numberBase, number));

                                               }

                                               catch(Exception
ex)

                                               {

                                                               Console.WriteLine(ex.Message);

                                               }

                                               Console.ReadKey();

                               }

                              

                              

                               public static string GetDec2Any(int
numberBase, int number)

                               {

                                               const string ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";                                                                                       

                                               StringBuilder remainder = new
StringBuilder();

 

                                               while(numberBase <=  number)

                                               {

                                                               remainder.Insert(0,
ABC[number % numberBase]);

                                                               number
=  number / numberBase;                                                                                                                                                             

                                               }

 

                                               remainder.Insert(0,
ABC[number % numberBase]);

                                               return remainder.ToString();

                               }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s