3
I’m having a problem trying to add numbers that are in a variable, because it’s taking the ASCII Code from the same.
How do I directly pick the number that is within 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 on Ideone.
For example, let’s say i
has the value 1
, it would be right for him to catch the 0
of bin[1]
, multiply by 10 and raise to 6 power, which would give 0. But the code is taking the bin[1]
and representing it as 48, which would be the value of it in ASCII Table.