Created
August 18, 2020 14:25
-
-
Save parzibyte/dd00b87c0f1bbba06411236e65b1d149 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 textToBinary(String originalText) { | |
String binaryText = ""; | |
for (int i = 0; i < originalText.length(); i++) { | |
// Primero obtenemos la letra o carácter actual | |
char currentChar = originalText.charAt(i); | |
// Necesitamos obtener su representación entera ASCII | |
int ascii = (int) currentChar; | |
// Una vez que ya tenemos el entero, lo convertimos a binario | |
String binary = decimalToBinary(ascii); | |
// Lo agregamos a la cadena resultante agregando además un espacio | |
binaryText += binary + " "; | |
} | |
// Finalmente regresamos el texto | |
return binaryText; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment