Skip to content

Instantly share code, notes, and snippets.

@escottalexander
Created February 18, 2018 23:28
Show Gist options
  • Save escottalexander/b93de741a089fe8fe5595e00a4fcfa70 to your computer and use it in GitHub Desktop.
Save escottalexander/b93de741a089fe8fe5595e00a4fcfa70 to your computer and use it in GitHub Desktop.
function binaryAgent(str) {
var binArr = [];
str = str.split(" ");
for (var i = 0; i < str.length; i++) {
binArr.push(String.fromCharCode(parseInt(str[i], 2)));
}
str = binArr.join("");
console.log(str)
return str;
}
function convertToBinary(str) {
var binArr = [];
var arr = str.split("");
for (var i = 0; i < arr.length; i++) {
binArr.push(str.charCodeAt(i).toString(2));
}
str = binArr.join(" ");
console.log(str);
return str;
}
//convertToBinary("Enter text here and uncomment")
//binaryAgent("Enter binary here and uncomment to reveal the meaning")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment