Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function binaryAgent(str) {
- alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.':;?!,() ";
- alphSp = alph.split('');
- newStr = [];
- newStr = str.split(' ');
- arr = [];
- holder = 0;
- binHash = {};
- bin = [1000001, 1000010, 1000011, 1000100, 1000101, 1000110, 1000111, 1001000, 1001001, 1001010, 1001011, 1001100, 1001101, 1001110, 1001111, 1010000, 1010001, 1010010, 1010011, 1010100, 1010101, 1010110, 1010111, 1011000, 1011001, 1011010, 1100001, 1100010, 1100011, 1100100, 1100101, 1100110, 1100111, 1101000, 1101001, 1101010, 1101011, 1101100, 1101101, 1101110, 1101111, 1110000, 1110001, 1110010, 1110011, 1110100, 1110101, 1110110, 1110111, 1111000, 1111001, 1111010, 101110, 100111, 111010, 111011, 111111, 100001, 101100, 101000, 101001, 100000];
- for(i = 0; i < newStr.length; i++){
- newStr[i] = Number(newStr[i]);
- holder = newStr[i];
- console.log(parseInt(holder, 2));
- if(newStr[i] === 110111){
- arr.push("'");
- }
- console.log(' this is index ' + alphSp[bin.indexOf(newStr[i])] + ' in bin');
- arr.push(alphSp[bin.indexOf(newStr[i])]);
- }
- arr = arr.join("");
- console.log("'");
- return arr;
- }
- binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
- /*
- binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111") should return "Aren't bonfires fun!?"
- binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001") should return "I love FreeCodeCamp!"
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement