How can I convert Binary code to text using JavaScript? I have already made it convert text to binary but is there a way of doing it the other way around?
Here is my code:
function convertBinary() {
var output = document.getElementById("outputBinary");
var input = document.getElementById("inputBinary").value;
output.value = "";
for (i = 0; i < input.length; i++) {
var e = input[i].charCodeAt(0);
var s = "";
do {
var a = e % 2;
e = (e - a) / 2;
s = a + s;
} while (e != 0);
while (s.length < 8) {
s = "0" + s;
}
output.value += s;
}
}
<div class="container">
<span class="main">Binary Converter</span><br>
<textarea autofocus class="inputBinary" id="inputBinary" onKeyUp="convertBinary()"></textarea>
<textarea class="outputBinary" id="outputBinary" readonly></textarea>
<div class="about">Made by <strong>Omar</strong></div>
</div>