Decimal representation of given binary string is divisible by 20 or not | function to check whether decimal representation of given binary number is divisible by 10 or not ; if last digit is '1' , then number is not divisible by 10 ; to accumulate the sum of last digits in perfect powers of 2 ; traverse from the 2 nd last up to 1 st digit in ' bin ' ; if digit in '1' ; calculate digit 's position from  the right ; according to the digit 's position,  obtain the last digit of the  applicable perfect power of 2 ; if last digit is 0 , then divisible by 10 ; not divisible by 10 ; function to check whether decimal representation of given binary number is divisible by 20 or not ; if ' bin ' is an odd number ; check if bin ( 0. . n - 2 ) is divisible by 10 or not ; Driver program to test above
function isDivisibleBy10 ( bin , n ) { if ( bin [ n - 1 ] == ' ' ) return false ; var sum = 0 ; for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( bin [ i ] == ' ' ) { var posFromRight = n - i - 1 ; if ( posFromRight % 4 == 1 ) sum = sum + 2 ; else if ( posFromRight % 4 == 2 ) sum = sum + 4 ; else if ( posFromRight % 4 == 3 ) sum = sum + 8 ; else if ( posFromRight % 4 == 0 ) sum = sum + 6 ; } } if ( sum % 10 == 0 ) return true ; return false ; } function isDivisibleBy20 ( bin , n ) { if ( bin [ n - 1 ] == ' ' ) return false ; return isDivisibleBy10 ( bin , n - 1 ) ; } var bin = " " ; var n = bin . length ; if ( isDivisibleBy20 ( bin , n - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ;