C# Program to convert Decimal to Binary

In this post, we will learn about C# Program to convert Decimal to Binary with an example.

Description:

In my previous posts I have explained various topics like Get site visitor count in asp.net
Convert generic list to datatable in Asp.Net C#.Net, Abstract Class in C# with Example,
Routing in Asp.Net MVC with Example
,Use of Global.asax in Asp.net




Now in this post, I will explain C# Program to convert Decimal to Binary with appropriate example.

Now create Console Application in Visual Studio and write below lines of code in it.

using System;
namespace DotNetK
{
    class Program
    {
        static void Main(string[] args)
        {
            // C# Program to convert Decimal to Binary

            int _Number, i;
            int[] a = new int[10];
            Console.Write("Enter the number to convert to binary: ");
            _Number = int.Parse(Console.ReadLine());
            for (i = 0; _Number > 0; i++)
            {
                a[i] = _Number % 2;
                _Number = _Number / 2;
            }
            Console.Write("Binary of the given number= ");
            for (i = i - 1; i >= 0; i--)
            {
                Console.Write(a[i]);
            }     

            Console.ReadKey(); // To hold the console screen.
        }
    }
}



Read :

Summary

You can also read about ASP.NET, C#.Net, JQUERY, AJAX, JavaScript
I hope you get an idea about C# Program to convert Decimal to Binary.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you liked this post, don’t forget to share this.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website