-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryAgent.js
More file actions
25 lines (21 loc) · 1011 Bytes
/
binaryAgent.js
File metadata and controls
25 lines (21 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function binaryAgent(str) {
// convert the string into an array of binary digits
// var binary = str.split(' ');
// var digits = [];
// binary.map(function(nums) {
// digits.push(parseInt(nums, 2));
// });
// return digits.map(function(digit) {
// return String.fromCharCode(digit);
// }).join('');
//console.log(binary);
// convert the string into an array of binary digits
var binary = str.split(' ');
// iterate over the array, convert every 'binary' string into a decimal using the parseInt() method
// then convert every ASCII number(decimal) into a letter and return the string using the join() method
return binary.map(function(num) {
//console.log(String.fromCharCode(parseInt(num, 2)));
return String.fromCharCode(parseInt(num, 2));
}).join('');
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");