using System; class BinToDec2 { public static void Main(string[] args) { { String bin_1;//creates string to store binary number Console.WriteLine("Welcome, to....."); Console.WriteLine("Binary to Decimal Conversion, Version 2.0");//Introduces program Console.WriteLine();//blank line Console.WriteLine("Please enter the positive binary number you wish to convert to decimal."); //requests input from user bin_1 = Console.ReadLine();//stores input form user for binary number int I=bin_1.Length;//counts characters in length from binary number int dec_1;//creates integer to store decimal number int P=1;//let P equal to 2^1 dec_1 = 0;//gives decimal a beginning value of 0 while(true){//starts loop if(I==0) break;//break loop once I = 0 I=I - 1;//subtracts 1 from I so, that once at 0, will break loop if (bin_1[I] == '1')//If binary digit is 1, do the following dec_1 = dec_1 + P;//if binary digit is one, add dec_1 to P P=P * 2;//updates P to be equal to 2^I }//ends loop Console.WriteLine();//blank line Console.WriteLine();//blank line Console.WriteLine("Your Binary Number of {0}", bin_1);//repeats users binary number Console.WriteLine("is equal to the Decimal Number {0}.", dec_1.ToString() ); //displays solution to user Console.WriteLine();//blank line Console.WriteLine();//blank line Console.WriteLine();//blank line Console.WriteLine("Thank You For Using Binary to Decimal Conversion.");//thanks user Console.WriteLine("Hit the Enter Key to Exit.");//instructs user to hit enter to end Console.ReadLine();//waits for input to end program } } }