Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Convertions
- {
- class Program
- {
- public static string ConvertFromBase_10_To_Base_2 (int base10)
- {
- int remainder;
- string result_base2="";
- while(base10!=0)
- {
- remainder=base10%2;
- result_base2=remainder.ToString()+result_base2;
- base10=base10/2;
- }
- return result_base2;
- }
- static void Main(string[] args)
- {
- int base10;
- Console.WriteLine("Enter the decimal number you want to convert to the base of 2: ");
- string base2,base10temp = Console.ReadLine();
- while (int.TryParse(base10temp, out base10)==false)
- {
- Console.WriteLine("Wrong Input, Try Aagin: ");
- base10temp = Console.ReadLine();
- }
- base2=ConvertFromBase_10_To_Base_2(int.Parse(base10temp));
- Console.WriteLine(base10temp + "Equals " + base2);
- }
- }
- }
Add Comment
Please, Sign In to add comment