Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 11, 2020 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/fae9f3bb7caf7ca743424dcfd2b6e128 to your computer and use it in GitHub Desktop.
Save parzibyte/fae9f3bb7caf7ca743424dcfd2b6e128 to your computer and use it in GitHub Desktop.
public static long octalADecimal(String octal) {
long decimal = 0;
int potencia = 0;
for (int x = octal.length() - 1; x >= 0; x--) {
int valorActual = Character.getNumericValue(octal.charAt(x));
long elevado = (long) Math.pow(8, potencia) * valorActual;
decimal += elevado;
potencia++;
}
return decimal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment