I'm working on a school assignment where I have to convert a 8 bit binary number to decimal. This is my code;
private void btnCalculate_Click(object sender, EventArgs e)
{
string invoer = txtBoxInput.Text;
// binair naar decimaal
if (rdBtnBinair.Checked == true)
{
int invoerlengte = invoer.Length;
double nieuwgetal = 0;
for (int i = 0; i <= invoerlengte; i++)
{
if (int.Parse(invoer.Substring(i, 1)) == 1)
{
nieuwgetal += Math.Pow(2,(i+1));
}
}
txtBoxOutput.Text = nieuwgetal.ToString();
In C#. Error im getting: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Think my code should be good, don't see whats wrong. Regards