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 binaryusing System;
class Program{
static void Main(string[] args){
try{
int i = (int)Convert.ToInt32(args[0]);
Console.WriteLine("\n{0} converted to Binary is {1}\n",i,ToBin(i));
}catch(Exception e){
Console.WriteLine("\n{0}\n",e.Message);
}
}//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();
Array.Reverse(BinArray);
Bin = new string(BinArray);
return Bin;
}
}