// Arrays may not be used to contain the binary digits entered by the user
// Determining the decimal equivalent of a particular binary digit in the sequence must be calculated using a single mathematical function,
// for example the natural logarithm. It's up to you to figure out which function to use.
// User can enter up to 8 binary digits in one input field
// User must be notified if anything other than a 0 or 1 was entered
// User views the results in a single output field containing the decimal (base 10) equivalent of the binary number that was entered
// int numberInput = 0;
Console.WriteLine("Input up to 8 binary digits: ");
String userInput = Console.ReadLine();
// bool isParseable = Int32.TryParse(userInput, out numberInput);
int index = 0;
int finalResult = 0;
for (int i=0; i < userInput.Length; i++)
{
if (userInput[i] = "0")
{
GetPow(2, index);
finalResult += index;
System.Console.WriteLine(finalResult);
index++;
}
}
static int GetPow(int baseNum, int powNum)
{
int result = 1;
for (int i = 0; i < powNum; i++)
{
result = result * baseNum;
}
return result;
}
// Arrays may not be used to contain the binary digits entered by the user
// Determining the decimal equivalent of a particular binary digit in the sequence must be calculated using a single mathematical function,
// for example the natural logarithm. It's up to you to figure out which function to use.
// User can enter up to 8 binary digits in one input field
// User must be notified if anything other than a 0 or 1 was entered
// User views the results in a single output field containing the decimal (base 10) equivalent of the binary number that was entered
// int numberInput = 0;
Console.WriteLine("Input up to 8 binary digits: ");
String userInput = Console.ReadLine();
// bool isParseable = Int32.TryParse(userInput, out numberInput);
int index = 0;
int finalResult = 0;
for (int i=0; i < userInput.Length; i++)
{
if (userInput[i] = "0")
{
GetPow(2, index);
finalResult += index;
System.Console.WriteLine(finalResult);
index++;
}
}
static int GetPow(int baseNum, int powNum)
{
int result = 1;
for (int i = 0; i < powNum; i++)
{
result = result * baseNum;
}
return result;
}