I am newbie in C#, however I have tried to write code for converting Decimal to binary, i know there are a lot other ways and probably a lot easier ways, but i just wanted to try it this way - with List. Can someone please tell me what I`m doing wrong ? Thanks!
static void Main(string[] args)
{
long decimalNum = long.Parse(Console.ReadLine());
long divideNumber = decimalNum;
List<string> BinaryResult = new List<string>();
for (int i = 0; divideNumber == 0; i++)
{
long divideBytwo = divideNumber % 2;
if (divideBytwo == 1)
{
BinaryResult.Add("1");
}
if (divideBytwo == 0)
{
BinaryResult.Add("0");
}
divideNumber /= 2;
}
for (int i = 0; i < BinaryResult.Count; i++)
{
Console.Write(BinaryResult[BinaryResult.Count - i]);
}
}
Is there a way with integer list too or .. Am I completely wrong ?