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("");
}
binaryAgent('01000001 01110010 01100101 01101110 00100111 01110100');
//translates to "Aren't"
function stringToBinary(str) {
let strOut = "";
for (var i = 0; i < str.length; i++) {
strOut += str[i].charCodeAt(0).toString(2);
}
return strOut
}
// string to binary
parseInt(num.toString(2));
// binary to string
parseInt(num.toString(2), 2);
// Text to Binary
function text2Binary(string) {
return string.split('').map(function (char) {
return char.charCodeAt(0).toString(2);
}).join(' ');
}
text2Binary("Hello World");
let num = 2020;
let x = +num.toString(2);
console.log(x);