We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, June 12, 2015

Convert to Binary to Decimal in C#


class Program

    {

        static void Main(string[] args)

        {

            int n, binary, decml = 0, a = 1, reminder;

            Console.WriteLine("Enter the Binary number which is 0 and 1 format");

            n = int.Parse(Console.ReadLine());

            binary = n;

            while (n > 0)

            {

                reminder = n % 10;

                decml = decml + reminder * a;

                n = n / 10;

                a = a * 2;

            }

            Console.WriteLine("The Binary number is " + binary);

            Console.WriteLine("The Deciaml number is :" + decml);

            Console.WriteLine();

            Console.ReadLine();

        } 

    }

}
output:


No comments: