Advertisement
Mvelchev

Untitled

May 30th, 2022
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function toDecimal(a){
  2.     let binary= '';
  3.     if (typeof a == 'string'){
  4.         binary = a.split();
  5.     } else {
  6.         binary = a.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(00001001));
  15.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement