This C# Program Performs Binary to Decimal Conversion. This C# Program converts the given binary number into decimal. The program reads the binary number, does a modulo operation to get the remainder, multiples the total by base 2 and adds the modulo and repeats the steps.

Here is source code of the C# Program to Perform Binary to Decimal Conversion.The C# program is successfully compiled and executed with Microsoft Visual Studio.The program output is also shown below.

`/*`

`* C# Program to Perform Binary to Decimal Conversion`

`*/`

using System;

using System.Collections.Generic;

using System.Text;

`namespace Program`

`{`

`class Program`

`{`

static void Main(string[] args)

`{`

int num, binary_val, decimal_val = 0, base_val = 1, rem;

Console.Write("Enter a Binary Number(1s and 0s) : ");

num = int.Parse(Console.ReadLine()); /* maximum five digits */

binary_val = num;

while (num > 0)

`{`

rem = num % 10;

decimal_val = decimal_val + rem * base_val;

num = num / 10 ;

base_val = base_val * 2;

`}`

Console.Write("The Binary Number is : "+binary_val);

Console.Write("\nIts Decimal Equivalent is : "+decimal_val);

Console.ReadLine();

`}`

`}`

`}`

Here is the output of the C# Program:

Enter a Binary Number(1s and 0s) : 101010 The Binary Number is : 101010 Its Decimal Equivalent is : 42

**Sanfoundry Global Education & Learning Series – 1000 C# Programs.**

If you wish to look at all C# Programming examples, go to 1000 C# Programs.