Write a C# program to convert Binary number into Decimal number.

Write a C# program to convert Binary number into Decimal number.

Last updated:11/30/2021 3:39:23 AM

1 Answers

Manish Manish
Manish Manish

Following C# program is to convert the Binary number into Decimal number,

using System;

public class Program
{
 public static void Main()
 {
    int binary;
   int weight=1;
   int number=0;
   int rem;
   Console.WriteLine('enter the binary number');
   binary=int.Parse(Console.ReadLine());
   while(binary!=0)
   {
           rem=binary%10;
           number=number+rem*weight;
           binary=binary/10;
           weight *=2;
   }
    Console.WriteLine('Decimal number is :'+number);     
}
}

Output:

enter the binary number

111111
Decimal number is :63

Answer