| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2c5e1e7 commit fd1025e
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,14 @@ | |||
| 1 | - function binaryToDeicmal (binaryNumber) { | ||
| 1 | + const binaryToDecimal = (binaryString) => { | ||
| 2 | 2 | let decimalNumber = 0 | |
| 3 | - const binaryDigits = binaryNumber.split('').reverse() // Splits the binary number into reversed single digits | ||
| 3 | + const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits | ||
| 4 | 4 | binaryDigits.forEach((binaryDigit, index) => { | |
| 5 | 5 | decimalNumber += binaryDigit * (Math.pow(2, index)) // Summation of all the decimal converted digits | |
| 6 | 6 | }) | |
| 7 | - console.log(`Decimal of ${binaryNumber} is ${decimalNumber}`) | ||
| 7 | + console.log(`Decimal of ${binaryString} is ${decimalNumber}`) | ||
| 8 | + return decimalNumber | ||
| 8 | 9 | } | |
| 9 | 10 | ||
| 10 | - binaryToDeicmal('111001') | ||
| 11 | - binaryToDeicmal('101') | ||
| 11 | + (() => { | ||
| 12 | + binaryToDecimal('111001') | ||
| 13 | + binaryToDecimal('101') | ||
| 14 | + })() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments