Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

Converting Binary to text using javascript

$
0
0

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;
  }
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><center><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></center>

Any help will be greatly appreciated.

Thanks, Omar.


Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>