Binary to Decimal Conversion in C#
Posted by Samath
Last Updated: January 10, 2021

Write a C# program that ask the user for a binary number and convert the number entered into decimal. a binary number is a number expressed in the base-2 numeral system, which uses only two symbols: 0 and 1.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BinarytoDecimalConversion
{
    public partial class frmBinarytoDecimalConversion : Form
    {
        public frmBinarytoDecimalConversion()
        {
            InitializeComponent();
        }

        private void btnconvert_Click(object sender, EventArgs e)
        {


            int bin_Num = int.Parse(txtinput.Text);
            int dec_Num = 0;

            int ba = 1;

            while (bin_Num > 0)
            {
                int rem_Value = bin_Num % 10;
                bin_Num = bin_Num / 10;
                dec_Num += rem_Value * ba;
                ba = ba * 2;
            }

            txtoutput.Text = dec_Num.ToString();

        }
    }
}