human
Write me a code to sum of Bitwise AND of each array element with the elements of another array and the other steps required given the following:
Sum of Bitwise AND of each array element with the elements of another array | Function to compute the AND sum for each element of an array.
Declaring an array of size 32 for storing the count of each bit.
Traverse the array arr2 [ ] and store the count of a bit in frequency array.
Current bit position.
While num is greater than 0.
Checks if ith bit is set or not.
Increment the count of bit by one.
Increment the bit position by one.
Right shift the num by one.
Traverse in the arr2 [ ].
Store the ith bit value.
Total required sum.
Traverse in the range [ 0 , 31 ].
Checks if current bit is set.
Increment the bitwise sum by frequency [ bit_position ] * value_at_that_bit.
Right shift num by one.
Left shift vale_at_that_bit by one.
Print sum obtained for ith number in arr1 [ ].
Driver Code.
Given arr1 [ ].
Given arr2.
Size of arr1 [ ].
Size of arr2 [ ].
Function Call"
How can the above be solved in Python?
assistant
#Here is code to sum of Bitwise AND of each array element with the elements of another array and the other steps required.
 def Bitwise_AND_sum_i ( arr1 , arr2 , M , N ) :
	frequency = [ 0 ] * 32
	for i in range ( N ) :
		bit_position = 0
		num = arr1 [ i ]
		while ( num ) :
			if ( num & 1 ) :
				frequency [ bit_position ] += 1
			bit_position += 1
			num >>= 1
	for i in range ( M ) :
		num = arr2 [ i ]
		value_at_that_bit = 1
		bitwise_AND_sum = 0
		for bit_position in range ( 32 ) :
			if ( num & 1 ) :
				bitwise_AND_sum += frequency [ bit_position ] * value_at_that_bit
			num >>= 1
			value_at_that_bit <<= 1
		print ( bitwise_AND_sum , end = " ▁ " )
	return
if __name__ == ' _ _ main _ _ ' :
	arr1 = [ 1 , 2 , 3 ]
	arr2 = [ 1 , 2 , 3 ]
	N = len ( arr1 )
	M = len ( arr2 )
	Bitwise_AND_sum_i ( arr1 , arr2 , M , N )