Skip to content

Instantly share code, notes, and snippets.

@aashutoshrathi
Last active March 15, 2019 15:28
Show Gist options
  • Save aashutoshrathi/b3720ec7a6ed3183be6feacc7a87191f to your computer and use it in GitHub Desktop.
Save aashutoshrathi/b3720ec7a6ed3183be6feacc7a87191f to your computer and use it in GitHub Desktop.
function binaryAgent(str) {
var newBin = str.split(" ");
var binCode = [];
for (i = 0; i < newBin.length; i++) {
binCode.push(String.fromCharCode(parseInt(newBin[i], 2)));
}
return binCode.join("");
}
function textToBin(text) {
var length = text.length,
output = [];
for (var i = 0;i < length; i++) {
var bin = text[i].charCodeAt().toString(2);
output.push(Array(8-bin.length+1).join("0") + bin);
}
return output.join(" ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment