Binary Agents
Pass in the binary string, translate into English sentences and return.
Binary strings are separated by a space.
String.charcodeat ()
String.fromCharCode ()
Ideas:
(1) Convert strings into arrays;
(2) Convert binary into decimal in array;
(3) Convert the decimal digits in the array into letters;
(4) Convert the array into a string;
Knowledge points
(1) the String.Split () 方法将一个
String
object is segmented into a string array, and 通过
the string is divided into substrings;
(2) parseint (string,num) num stands for num, this method can convert any number of binary to decimal;
Accordingly, a.tostring (num), this method can convert decimal into any number of binary;
(3) The String.fromCharCode () method returns a string created using the specified sequence of Unicode values.
Code:
1 functionbinaryagent (str) {2 varArr=str.split (' ');3 for(vari=0;i<arr.length;i++){4Arr[i]=parseint (arr[i],2);5arr[i]=String.fromCharCode (Arr[i]);6 }7Str=arr.join (' ');8 returnstr;9 }Ten OneBinaryagent ("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 0 1110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111 ");
The FCC intermediate algorithm problem Binary Agents