human
Bitwise and ( or & ) of a range | Find position of MSB in n . For example if n = 17 , then position of MSB is 4. If n = 7 , value of MSB is 3.
Function to find Bit - wise & of all numbers from x to y ..
res = 0 Initialize result.
Find positions of MSB in x and y.
If positions are not same , return.
Add 2 ^ msb_p1 to result.
subtract 2 ^ msb_p1 from x and y ..
Driver code"
Solution in Python:
 ... Write me a code to bitwise and ( or & ) of a range and the other steps required?
assistant
#Here is code to bitwise and ( or & ) of a range and the other steps required.
 def msbPos ( n ) :
	msb_p = - 1
	while ( n > 0 ) :
		n = n >> 1
		msb_p += 1
	return msb_p
def andOperator ( x , y ) :
	while ( x > 0 and y > 0 ) :
		msb_p1 = msbPos ( x )
		msb_p2 = msbPos ( y )
		if ( msb_p1 != msb_p2 ) :
			break
		msb_val = ( 1 << msb_p1 )
		res = res + msb_val
		x = x - msb_val
		y = y - msb_val
	return res
x , y = 10 , 15
print ( andOperator ( x , y ) )