public int OctToDecimal(string data)
{
int result = 0;
char[] numbers = data.ToCharArray();
int ASCIIZero = 48;
int ASCIIEight = 56;
try
{
if (!IsNumeric(data))
error = "Invalid Value - This is not a numeric value";
else
{
for (int counter = numbers.Length; counter > 0; counter--)
{
byte[] ascii = Encoding.ASCII.GetBytes (numbers[counter - 1].ToString ());
if ((int.Parse ( ascii[0].ToString ()) < ASCIIZero ) && (int.Parse ( ascii[0].ToString ()) > ASCIIEight ))
error = "Invalid Value - This is not a oct number";
else
{
int num = int.Parse(numbers[counter - 1].ToString());
int exp = numbers.Length - counter;
result += (Convert.ToInt16(Math.Pow(8, exp)) * num);
}
}
}
}
catch (Exception ex)
{
error = ex.Message;
}
return result;
}
{
int result = 0;
char[] numbers = data.ToCharArray();
int ASCIIZero = 48;
int ASCIIEight = 56;
try
{
if (!IsNumeric(data))
error = "Invalid Value - This is not a numeric value";
else
{
for (int counter = numbers.Length; counter > 0; counter--)
{
byte[] ascii = Encoding.ASCII.GetBytes (numbers[counter - 1].ToString ());
if ((int.Parse ( ascii[0].ToString ()) < ASCIIZero ) && (int.Parse ( ascii[0].ToString ()) > ASCIIEight ))
error = "Invalid Value - This is not a oct number";
else
{
int num = int.Parse(numbers[counter - 1].ToString());
int exp = numbers.Length - counter;
result += (Convert.ToInt16(Math.Pow(8, exp)) * num);
}
}
}
}
catch (Exception ex)
{
error = ex.Message;
}
return result;
}
Add a comment