Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. function dec2bin(dec){
  2. return (dec >>> 0).toString(2); // >>> zero fill right shift due to signed bit
  3. }
  4.  
  5. function bin2exclamation(bin){
  6. var arr = [];
  7. for(var i=0; i< bin.length; i++){
  8. arr.push(parseInt(bin.substr(i, 1)) === 1 ? 0 : 1);
  9. }
  10. return arr.join('');
  11. }
  12.  
  13. function bin2int(bin){
  14. return parseInt(bin, 2);
  15. }
  16.  
  17. var init = 100;
  18. init = dec2bin(init);
  19. console.log(init);
  20.  
  21. init = bin2exclamation(init);
  22. console.log(init);
  23.  
  24. init = bin2int(init);
  25. console.log(init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement