Tell us what’s happening:
I for the life of me cannot seem to figure out how to convert the binary to decimal properly. I’m confident that that is my only real issue. I’m trying to use doubling but I’m not quite sure what I’m doing wrong. Maybe I’m just not understanding how to do the conversion properly. Anyway advice is very much appreciated.
Your code so far
function binaryAgent(str) {
let res = 0;
let split = str.split(' ');
let oneArr = split[0].slice();
let bin = 0;
let sum = 0;
let newArr = [];
//gives each section one by one
function oneAtAtime(one){
return one;
}
//supposed to convert the binary to decimal by doubling
function double (i,j){
return ( i * 2 + j);
}
for (let i = 0; i < split.length; i++){
(res = oneAtAtime(split[i]));
(bin = (res));
//supposed to push th edecimal of each binary into a new array
for(let i = 0, j = 1;i < bin.length, j < bin.length; i++, j++){
sum = (double(bin[i],bin[j]));
newArr.push(sum);
}
}
console.log(newArr);
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111")
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Intermediate Algorithm Scripting - Binary Agents
Link to the challenge: