Convert Decimal to binary

Omniitstudent
Posted by Omniitstudent under C# category on | Points: 40 | Views : 1998
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, bin =0, d=1;
for (int i = nNum1;i>0; i/=2)
{
rem =i % 2;
bin += rem * d;
d *= 10;
}
Console.WriteLine(bin);

Console.ReadLine();
}
}
}
//===========================================================================================
//// input--15
// output-1111

Comments or Responses

Login to post response