human
Bitwise OR ( or | ) of a range | Returns the Most Significant Bit Position ( MSB ).
Returns the Bitwise OR of all integers between L and R.
Find the MSB position in L.
Find the MSB position in R.
Add this value until msb_p1 and msb_p2 are same.
.
Calculate msb_p1 and msb_p2.
Find the max of msb_p1 and msb_p2.
Set all the bits from msb_p1 upto 0 th bit in the result.
Driver Code"
Solution in Python:
 What is a code to bitwise OR ( or and the other steps required?
assistant
#Here is code to bitwise OR ( or and the other steps required.
 def MSBPosition ( N ) :
	msb_p = - 1
	while ( N ) :
		N = N >> 1
		msb_p += 1
	return msb_p
def findBitwiseOR ( L , R ) :
	res = 0
	msb_p1 = MSBPosition ( L )
	msb_p2 = MSBPosition ( R )
	while ( msb_p1 == msb_p2 ) :
		res_val = ( 1 << msb_p1 )
		res += res_val
		L -= res_val
		R -= res_val
		msb_p1 = MSBPosition ( L )
		msb_p2 = MSBPosition ( R )
	msb_p1 = max ( msb_p1 , msb_p2 )
	for i in range ( msb_p1 , - 1 , - 1 ) :
		res_val = ( 1 << i )
		res += res_val
	return res
if __name__ == " _ _ main _ _ " :
	L , R = 12 , 18
	print ( findBitwiseOR ( L , R ) )