TheBulgarianWolf

Convert From Binary To Decimal

Dec 29th, 2020
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function convertFromBinaryToDecimal(binaryNumber){
  2.     let sum = 0;
  3.     let position = 0;
  4.     for(let i = binaryNumber.length-1;i>=0;i--){
  5.         let currentDigit = Number(binaryNumber[i]);
  6.         sum += currentDigit*(2 ** position);
  7.         position++;
  8.     }
  9.     console.log(sum);
  10. }
  11.  
  12.  
  13.  //Change the number if you want
  14. convertFromBinaryToDecimal('1010');
Add Comment
Please, Sign In to add comment