C# Program to Converter a Binary to Decimal

You are Here:

Converter a Number from Binary to Decimal

In the following example, we will convert a Binary number (1000001) to a Decimal number (65).

Tips: It is recommended to use our online Binary to Decimal converter for better understanding.

Example

C# Compiler
using System; namespace myApp { class Program { static void Main(string[] args) { int num = 1000001; int[] arr = new int[50]; int i = -1, j; int total = 0; while(num != 0) { i++; arr[i] = num % 10; num = num / 10; } for(j=i; j>=0; j--) total += (arr[j] * ((int) Math.Pow(2, j))); Console.Write("Decimal number of 1000001 (binary) is {0}", total); } } }

Output

Decimal number of 1000001 (binary) is 65

Converter any Given Binary Number to Decimal Number

In the following example, we will convert any given binary number to a decimal number.

Example

C# Compiler
using System; namespace myApp { class Program { static void Main(string[] args) { int num, copyNum; int[] arr = new int[50]; int i = -1, j; int total = 0; Console.Write("Enter a Binary number: "); num = Convert.ToInt32(Console.ReadLine()); copyNum = num; while(copyNum != 0) { i++; arr[i] = copyNum % 10; copyNum = copyNum / 10; } for(j=i; j>=0; j--) total += (arr[j] * ((int) Math.Pow(2, j))); Console.Write("Decimal number of {0} (binary) is {1}", num, total); } } }

Output

Enter a Binary number: 10 Decimal number of 10 (binary) is 2

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on C# with examples for quick and easy learning.

We are working to cover every Single Concept in C#.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author