/******************************************************/ /* Introduction to Programming */ /* By Dr. ANTF */ /* www.antf.net */ /* Copyright 2015 */ /* */ /* C# 321 - Problem 20: Binary to Decimal */ /******************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DOS { class Program { static void Main(string[] args) { int bin, sum = 0, counter = 0, power; Console.Write("Please entere a binary number: "); bin = int.Parse(Console.ReadLine()); while(bin != 0) { //get the power of 2 power = 1; for (int i = 0; i < counter; i++) power = power * 2; sum = sum + (power * (bin % 10)); bin = bin / 10; //increment the couter counter++; } Console.WriteLine("\n\nThe decimal value is: {0}", sum); Console.ReadKey(); } } }