Created
April 2, 2018 16:47
-
-
Save nickihastings/4f2a829d2465fed65fac4d0f5fafbf2b to your computer and use it in GitHub Desktop.
Return an English translated sentence of the passed binary string. The binary string will be space separated.
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 binaryAgent(str) { | |
var arr = str.split(' '); | |
//var words = []; | |
for(var i =0; i<arr.length; i++){ | |
arr[i] = parseInt(arr[i], 2); | |
arr[i] = String.fromCharCode(arr[i]); | |
//can also write the above as: | |
//words.push(String.fromCharCode(parseInt(arr[i], 2))); | |
//parses first then converts to letter then pushes to array. | |
} | |
return arr.join(''); | |
} | |
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment