human
Give me a code to find array elements with rightmost set bit at the position of the rightmost set bit in K and the other steps required given the following:
Find array elements with rightmost set bit at the position of the rightmost set bit in K | Function to find the mask for finding rightmost set bit in K.
Function to find all array elements with rightmost set bit same as that in K.
Stores mask of K.
Store position of rightmost set bit.
Traverse the array.
Check if rightmost set bit of current array element is same as position of rightmost set bit in K.
Driver Code.
Input.
Function call to find the elements having same rightmost set bit as of K"
Solution in Python:
assistant
#Here is code to find array elements with rightmost set bit at the position of the rightmost set bit in K and the other steps required.
 def findMask ( K ) :
	mask = 1 ;
	while ( ( K & mask ) == 0 ) :
		mask = mask << 1 ;
	return mask ;
def sameRightSetBitPos ( arr , N , K ) :
	mask = findMask ( K ) ;
	pos = ( K & mask ) ;
	for i in range ( N ) :
		if ( ( arr [ i ] & mask ) == pos ) :
			print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 4 , 6 , 7 , 9 , 12 , 15 ] ;
	N = len ( arr ) ;
	K = 7 ;
	sameRightSetBitPos ( arr , N , K ) ;