using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BinaryToDecimal
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Enter Your Binary Number: “);
string c=Console.ReadLine();
int[] num = new int[100];
int p = 1;
int result=0;
for (int i = 0; i < c.Length; i++)
{
if (c[i] == ‘0’)
num[i] = 0;
else if (c[i] == ‘1’)
num[i] = 1;
}
for (int i=c.Length-1; i >=0; i–)
{
result = result + num[i] * p;
p = p * 2;
}
Console.WriteLine(“Your value in decimal is {0}”, result);
Console.ReadLine();
}
}
}
Thats nice but you can do it better like this, it saves you like 15 lines of code.
You can mail me for questions.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace binaryToDecimal
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Please enter your Binary Number: “);
string userBinaryInput = Console.ReadLine();
int binaryToDecimal = Convert.ToInt32(userBinaryInput, 2);
Console.WriteLine(“Your value in decimal is {0}”, binaryToDecimal);
Console.ReadKey();
}
}
}