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
1const binaryAgent = str => str.replace(/\d+./g, char => String.fromCharCode(`0b${char}`));
1How to convert string to array
2
3import java.util.*;
4
5public class GFG {
6
7 public static void main(String args[])
8 {
9
10 String str = "GeeksForGeeks";
11
12 // Creating array and Storing the array
13 // returned by toCharArray()
14 char[] ch = str.toCharArray();
15
16 // Printing array
17 for (char c : ch) {
18 System.out.println(c);
19 }
20 }
21}
22
1function dec2Bin(dec)
2{
3 if(dec >= 0) {
4 return dec.toString(2);
5 }
6 else {
7 /* Here you could represent the number in 2s compliment but this is not what
8 JS uses as its not sure how many bits are in your number range. There are
9 some suggestions https://stackoverflow.com/questions/10936600/javascript-decimal-to-binary-64-bit
10 */
11 return (~dec).toString(2);
12 }
13}
14
1function binaryAgent(str) {
2 const bytes = str.split(' ')
3 let output = ''
4
5 for (let k = 0; k < bytes.length; k++){
6 output += String.fromCharCode(parseInt(bytes[k], 2))
7 }
8
9 return output
10}
11
12binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
1function binaryAgent(str) {
2 let bytes = str.split(' ');
3 let output = '';
4
5 for (let k = 0; k < bytes.length; k++){
6 output += String.fromCharCode(convertToDecimal(bytes[k]));
7 }
8
9 return output;
10}
11
12function convertToDecimal(byte) {
13 let result = 0;
14
15 byte = byte.split('');
16
17 byte.reverse();
18
19 for (let a = 0; a < byte.length; a++){
20 if (byte[a] === '1'){
21 result += 2 ** a;
22 }
23 }
24
25 return result;
26}
27
28binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
29