I am trying to create a console application where the user inputs a base 10 number and the program outputs the number in binary.
I want to get the exact number of times to execute the for
loop to get correct value (the value HERE
in the code below).
I also have to reverse everything that the console is now outputting for everything to be correct but that I can do on my own later.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decimal_to_Binary
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a number and the computer will convert it into binary.");
string NumberIn = Console.ReadLine();
decimal Number = Decimal.Parse(NumberIn);
decimal[] Squared = new decimal[100];
for (int i = 0; i < HERE + 1; i++)
{
//Squared[i] = Math.Pow(2, i);
Squared[i] = 2 ^ i ;
if (Number == Squared[i])
{
Console.Write("1");
}
else
{
Console.Write("0");
}
}
Console.ReadKey();
}
}
}