DolF1NN
New Coder
When I input a binary number into the string variable "binary" say "0000" it returns 720, the number seems to be based on how many characters are in the string Binary, and the number exponentially increases the more digits. I dont know why this is... Could someone help me out?
My code is:
My code is:
Code:
using System;
public class Program
{
public static void Main()
{
string binary = "0000";
int binaryLength = binary.Length;
double binaryInt = 0;
for(int i = binaryLength; i > 0; i--)
{
binaryInt += (binary[i - 1]) * (Math.Pow(2, binaryLength - i));
Console.Write(binary[i - 1] + " ");
Console.WriteLine(Math.Pow(2, binaryLength - i) + " ");
}
Console.WriteLine();
Console.WriteLine(binaryInt);
}
}