Skip to content

Instantly share code, notes, and snippets.

@rfprod
Last active April 22, 2017 15:57
Show Gist options
  • Save rfprod/361804360631ea1ea2d0 to your computer and use it in GitHub Desktop.
Save rfprod/361804360631ea1ea2d0 to your computer and use it in GitHub Desktop.
Binary Agents
function binaryAgent(str) {
var inputBinArr = str.split(" ");
var convertedBinToDec = [];
var decodedBinArr = [];
var char = "";
var output = "";
for (var i=0;i<inputBinArr.length;i++){
char = String.fromCodePoint(convertBinToDec(inputBinArr[i]));
decodedBinArr.push(char);
}
function convertBinToDec(n){
var convert = 0;
var p = 0;
for (var z=n.length-1;z>=0;z--){
var multiplier = Math.pow(2,p);
convert = convert + n[z] * multiplier;
p = p + 1;
}
char = convert;
return char;
}
output = decodedBinArr.toString().replace(/,/g,"");
return output;
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");

Binary Agents

Returns an English translated sentence of the passed binary string. The binary string must be space separated.

A script by V.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment