octalToDec method

int octalToDec()

Calculate and return the decimal value of this octal integer

Implementation

int octalToDec(){
  if(this < 0){
    throw "Only positive integers can be converted from octal into dec using this library";
  }
  String octal = this.toString();
  int dec = 0;
  for(int n = (octal.length - 1); n >= 0; n--){
    int thisPositionLetter = int.parse(octal.substring(n, n + 1));
    if(thisPositionLetter < 0 || 7 < thisPositionLetter){
      throw "Integer cannot be interpreted as octal. It must be composed of characters that are within the range of 0 - 7.";
    }
    int thisExponent = (n - (octal.length - 1)).abs();
    dec += (thisPositionLetter * pow(8, thisExponent)).toInt();
  }
  return dec;
}