File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 1- function binaryToDeicmal ( binaryNumber ) {
1+ const binaryToDecimal = ( binaryString ) => {
22 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
44 binaryDigits . forEach ( ( binaryDigit , index ) => {
55 decimalNumber += binaryDigit * ( Math . pow ( 2 , index ) ) // Summation of all the decimal converted digits
66 } )
7- console . log ( `Decimal of ${ binaryNumber } is ${ decimalNumber } ` )
7+ console . log ( `Decimal of ${ binaryString } is ${ decimalNumber } ` )
8+ return decimalNumber
89}
910
10- binaryToDeicmal ( '111001' )
11- binaryToDeicmal ( '101' )
11+ ( ( ) => {
12+ binaryToDecimal ( '111001' )
13+ binaryToDecimal ( '101' )
14+ } ) ( )
You can’t perform that action at this time.
0 commit comments