Last active
March 15, 2019 15:28
-
-
Save aashutoshrathi/b3720ec7a6ed3183be6feacc7a87191f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 newBin = str.split(" "); | |
var binCode = []; | |
for (i = 0; i < newBin.length; i++) { | |
binCode.push(String.fromCharCode(parseInt(newBin[i], 2))); | |
} | |
return binCode.join(""); | |
} |
This file contains hidden or 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 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