Convert binary to decimal

Omniitstudent
Posted by Omniitstudent under C# category on | Points: 40 | Views : 2130
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication25
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("input the number");
int nNum1 = Convert.ToInt32(Console.ReadLine());
int rem = 1, dec =0, d=1;
for (int i = nNum1;i>0; i/=10)
{
rem =i % 10;
dec+= rem * d;
d *= 2;
}
Console.WriteLine(dec);

Console.ReadLine();
}
}
}
//===========================================================================================
//// input--1010
// output-10

Comments or Responses

Posted by: T.Saravanan on: 2/20/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi,

Kindly post your code inside the code tag.

Login to post response