C# Program to Convert a Binary Number Into a Decimal Number

We saw a lot of information in the previous article. We are going to know about this very clearly in the article C# Program to Convert a Binary Number Into a Decimal Number. I think you will like this article very much. Let’s go into the article.

C# Program to Convert a Binary Number Into a Decimal Number

C# Program to Convert a Binary Number Into a Decimal Number

//C# program to convert a binary number into a decimal number.

using System;

class Program
{
    static void Main(string[] args)
    {
        int binNum      = 0;
        int decNum      = 0;
        int i           = 0;
        int rem         = 0; 
        
        Console.Write("Enter a binary number: ");
        binNum = int.Parse(Console.ReadLine()); 
        

        while (binNum > 0)
        {
            rem = binNum % 10;
            decNum = decNum + rem * (int)Math.Pow(2, i);
            binNum = binNum / 10;
            i++;
        }
        Console.WriteLine("\nDecimal number: " + decNum);
    }
}
Enter a binary number: 0111

Decimal number: 7
Press any key to continue . . .

Final Words

C# Program to Convert a Binary Number Into a Decimal Number This article is your favorite topic because it is your favorite. And I will meet you in the next article.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment