Conversion of Decimal to Dinary number

This is the code writen in c sharp .by which we can simply convert a decimal number in to binary

using System;

class Program{

static void Main(string[] args){


int i = (int)Convert.ToInt32(args[0]);
Console.WriteLine("\n{0} converted to Binary is {1}\n",i,ToBin(i));

}catch(Exception e){



}//here the insilize the system

public static string ToBinary(Int32 Decimal)
//declare flag to need
Int32 Binflag;
char[] BinArray;
string Bin = "";

while (Decimal > 0)
Binflag = Decimal % 2;
Bin += Binflag ;
Decimal = Decimal / 2;

BinArray = Bin.ToCharArray();
Bin = new string(BinArray);

return Bin;



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: