I'm having a problem trying to add numbers that are in a variable, because you're getting the ASCII code from them.
How do I get the number directly inside a variable?
string bin = "1001001";
string final = "";
for (int i = 0; i < bin.Length; i++)
{
int j = bin[i];
final += Math.Pow(j * 10, bin.Length - i);
}
Console.WriteLine(final);
See working at Ideone .
For example, let's say that i
has the value 1
, the right one would be to get 0
bin[1]
, multiply by 10, and raise to 6 power, which would give 0. But code is taking bin[1]
and representing it 48, which would be the value of it in the ASCII Table.