Advertisement
Mvelchev

Untitled

May 30th, 2022
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function toDecimal(num){
  2.     let binary= '';
  3.     if (typeof num==='string'){
  4.         binary = num.split;
  5.     } else {
  6.         binary = num.toString().split();
  7.     }
  8.     let decimal = 0;
  9.     for (let i=0; i < binary.length; i++){
  10.         decimal = (decimal*2)+ binary[i];
  11.     }
  12.     return decimal;
  13. }
  14.     console.log(toDecimal(11110000));
  15.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement