We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c5e1e7 commit fd1025eCopy full SHA for fd1025e
Conversions/BinaryToDecimal.js
@@ -1,11 +1,14 @@
1
-function binaryToDeicmal (binaryNumber) {
+const binaryToDecimal = (binaryString) => {
2
let decimalNumber = 0
3
- const binaryDigits = binaryNumber.split('').reverse() // Splits the binary number into reversed single digits
+ const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits
4
binaryDigits.forEach((binaryDigit, index) => {
5
decimalNumber += binaryDigit * (Math.pow(2, index)) // Summation of all the decimal converted digits
6
})
7
- console.log(`Decimal of ${binaryNumber} is ${decimalNumber}`)
+ console.log(`Decimal of ${binaryString} is ${decimalNumber}`)
8
+ return decimalNumber
9
}
10
-binaryToDeicmal('111001')
11
-binaryToDeicmal('101')
+(() => {
12
+ binaryToDecimal('111001')
13
+ binaryToDecimal('101')
14
+})()
0 commit comments