Number with set bits only between L | Function to return the integer with all the bits set in range L - R ; iterate from L to R and add all powers of 2 ; Driver Code
< ? php function getInteger ( $ L , $ R ) { $ number = 0 ; for ( $ i = $ L ; $ i <= $ R ; $ i ++ ) $ number += pow ( 2 , $ i ) ; return $ number ; } $ L = 2 ; $ R = 5 ; echo getInteger ( $ L , $ R ) ; ? >