Last active
August 29, 2015 14:15
-
-
Save michaelrepper/675454dd83944fc94429 to your computer and use it in GitHub Desktop.
r/Dailyprogrammer Challenge #202 Easy - Binary to ASCII String
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
<!DOCTYPE html> | |
<html | |
<!-- Live preview of this Gist: | |
http://htmlpreview.github.io/?https://gist.githubusercontent.com/michaelrepper/675454dd83944fc94429/raw/47c36640e3e4dbacf039d6939f37355a7786915a/rdp_202_easy.htm | |
--> | |
<head> | |
<meta name="author" content="Michael Repper"> | |
<meta name="contact" content="query [ a * t ] gridoodle [ d * o * t ] com"> | |
<title>r/Dailyprogrammer Challenge #202 - Binary to ASCII String - Test Harness</title> | |
<script src="https://rawgit.com/michaelrepper/675454dd83944fc94429/raw/f6c19b3c98687f1cdb2a24e4bc87960304de7e5b/script.js"></script> | |
</head> | |
<body> | |
<div id="challenge"> | |
<p>r/Dailyprogrammer Challenge #202 Easy - Binary to ASCII String</p> | |
</div> | |
<div id="result"></div> | |
<script> | |
(function (){ | |
__init(); | |
})(); | |
</script> | |
</body> | |
</html> |
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
function bin_to_ascii_str(binary) | |
{ | |
var char = '', string = ''; | |
for (var i = 0; i < binary.length; i++) | |
{ | |
char += binary[i]; | |
if (i % 8 == 7) | |
{ | |
string += String.fromCharCode(parseInt(char, 2).toString(10)); | |
char = ''; | |
} | |
} | |
return string; | |
} | |
function __init() | |
{ | |
var binary = "0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100"; | |
document.getElementById("result").innerHTML = bin_to_ascii_str(binary); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment