Counting even decimal value substrings in a binary string | function return count of even decimal value substring ; store the count of even decimal value substring ; substring started with '0' ; increment result by ( n - i ) because all substring which are generated by this character produce even decimal value . ; Driver Code
< ? php function evenDecimalValue ( $ str , $ n ) { $ result = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ str [ $ i ] == '0' ) { $ result += ( $ n - $ i ) ; } } return $ result ; } $ str = "10010" ; $ n = 5 ; echo evenDecimalValue ( $ str , $ n ) ; return 0 ; ? >