1function binaryAgent(str) {
2
3var newBin = str.split(" ");
4var binCode = [];
5
6for (i = 0; i < newBin.length; i++) {
7 binCode.push(String.fromCharCode(parseInt(newBin[i], 2)));
8 }
9return binCode.join("");
10}
11binaryAgent('01000001 01110010 01100101 01101110 00100111 01110100');
12//translates to "Aren't"
13
1// string to binary
2parseInt(num.toString(2));
3
4// binary to string
5parseInt(num.toString(2), 2);
1/* From decimal to binary (similar fo rother base) */
2const num = 7;
3num.toString(2); // output: "111"
4
5/* From binary (similar fo rother base) to decimal */
6parseInt("111", 2); // output: 7
1function bin(num) {
2 var binn = [];
3 var c;
4 while (num != 1) {
5 c = Math.floor(num / 2);
6 binn.unshift(num % 2);
7 num = c;
8
9 }
10 binn.unshift(1)
11 return binn
12}
13//returns list of binary nos. in order
14
1function stringToBinary(str) {
2 let strOut = "";
3 for (var i = 0; i < str.length; i++) {
4 strOut += str[i].charCodeAt(0).toString(2);
5 }
6 return strOut
7}