Set all the bits in given range of a number | function to toggle bits in the given range ; calculating a number ' range ' having set bits in the range from l to r and all other bits as 0 ( or unset ) . ; Driver code
< ? php function setallbitgivenrange ( $ n , $ l , $ r ) { $ range = ( ( ( 1 << ( $ l - 1 ) ) - 1 ) ^ ( ( 1 << ( $ r ) ) - 1 ) ) ; return ( $ n $ range ) ; } $ n = 17 ; $ l = 2 ; $ r = 3 ; echo setallbitgivenrange ( $ n , $ l , $ r ) ; ? >