The FCC intermediate algorithm problem Binary Agents

Source: Internet
Author: User
Tags binary to decimal

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.