Advertisement
Guest User

Untitled

a guest
May 8th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function binaryAgent(str) {
  2. alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.':;?!,() ";
  3. alphSp = alph.split('');
  4. newStr = [];
  5. newStr = str.split(' ');
  6. arr = [];
  7. holder = 0;
  8. binHash = {};
  9. 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];
  10.  
  11.  
  12. for(i = 0; i < newStr.length; i++){
  13. newStr[i] = Number(newStr[i]);
  14. holder = newStr[i];
  15. console.log(parseInt(holder, 2));
  16. if(newStr[i] === 110111){
  17. arr.push("'");
  18. }
  19. console.log(' this is index ' + alphSp[bin.indexOf(newStr[i])] + ' in bin');
  20. arr.push(alphSp[bin.indexOf(newStr[i])]);
  21. }
  22.  
  23. arr = arr.join("");
  24.  
  25. console.log("'");
  26. return arr;
  27. }
  28.  
  29. binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
  30. /*
  31. 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!?"
  32. 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!"
  33. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement