© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
12 replies
REAL STUNNA

Binary To Decimal Program Help

Hi I'm having trouble trying to determine whether or not the current index in my inputted binary string is a 0 or 1. I've been trying to look for different ways to figure out how to do this, but I get stumped every time. Can someone push me in the right direction? Thank you.

// 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;
}
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

binary writer help
C#CC# / help
2y ago
Help binary trees BST
C#CC# / help
2y ago
Bank program help
C#CC# / help
12mo ago