Created
February 21, 2020 18:58
-
-
Save parzibyte/f28f095df7dbc0d2c300e4579a06a5eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String decimalAOctal(int decimal) { | |
String octal = "";// Almacenamos el número octal que será el resultado | |
String caracteresOctales = "01234567"; | |
while (decimal > 0) { | |
int residuo = decimal % 8; | |
// El residuo es lo que se suma, y podemos usarlo como índice | |
// Recordemos que el carácter se pone "a la izquierda", por eso | |
// concatenamos el carácter y luego lo que ya lleva sumado el octal | |
octal = (caracteresOctales.charAt(residuo) + octal); | |
// Lo vamos dividiendo entre 8 para que en algún momento llegue a 0 | |
decimal /= 8; | |
} | |
return octal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment