-
-
Save parzibyte/911c4c7f416273c52dfd3ddbdb4d44b1 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 convertirDecimalABinarioManual(long decimal) { | |
if (decimal <= 0) { | |
return "0"; | |
} | |
StringBuilder binario = new StringBuilder(); | |
while (decimal > 0) { | |
short residuo = (short) (decimal % 2); | |
decimal = decimal / 2; | |
// Insertar el dígito al inicio de la cadena | |
binario.insert(0, String.valueOf(residuo)); | |
} | |
return binario.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment