TheBulgarianWolf

Convert From Decimal To Binary

Dec 30th, 2020
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function convertDecimalToBinary(number){
  3.     let result = '';
  4.    
  5.     while(number > 0){
  6.         result = number%2 + result;
  7.         number = Math.trunc(number/2);
  8.     }
  9.    
  10.     console.log(result);
  11. }
  12.  
  13.  //Change the number if you want
  14. convertDecimalToBinary(11);
Add Comment
Please, Sign In to add comment