C# program to convert Binary Number to Decimal


Conversion of Binary To Decimal Number in C#

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.


using System;

namespace Hello
{
    class Number
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Program for number system conversion...!!!");
            int num, binary_val, decimal_val = 0, base_val = 1, rem;
            Console.Write("Enter the binary number: ");
            num = int.Parse(Console.ReadLine());
            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.WriteLine("Its Decimal Equivalent is : " + decimal_val);
            Console.ReadKey();
        }
    }
}

Happy Coding :)

Related Post:
C# program to convert Decimal Number to Binary
C# program to convert Decimal Number to Hexadecimal
C# program to convert Decimal Number to Octal

Comments

Popular posts from this blog

MultiSelection of Item in Recycler View

Upload Image From Android To Php Server

Merge Sort