Skip to content

Instantly share code, notes, and snippets.

@nickihastings
Created April 2, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickihastings/4f2a829d2465fed65fac4d0f5fafbf2b to your computer and use it in GitHub Desktop.
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.
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