Guest User

Untitled

a guest
Nov 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Convertions
  7. {
  8.     class Program
  9.     {
  10.         public static string ConvertFromBase_10_To_Base_2 (int base10)
  11.         {
  12.             int remainder;
  13.             string result_base2="";
  14.             while(base10!=0)
  15.             {
  16.                 remainder=base10%2;
  17.                 result_base2=remainder.ToString()+result_base2;
  18.                 base10=base10/2;
  19.             }
  20.                  return result_base2;
  21.  
  22.         }
  23.         static void Main(string[] args)
  24.         {
  25.             int base10;
  26.             Console.WriteLine("Enter the decimal number you want to convert to the base of 2: ");
  27.             string base2,base10temp = Console.ReadLine();
  28.             while (int.TryParse(base10temp, out base10)==false)
  29.             {
  30.                 Console.WriteLine("Wrong Input, Try Aagin: ");
  31.                 base10temp = Console.ReadLine();
  32.             }
  33.             base2=ConvertFromBase_10_To_Base_2(int.Parse(base10temp));
  34.             Console.WriteLine(base10temp + "Equals " + base2);
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment