Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active Mar 11, 2019
Embed
What would you like to do?
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