human
Write me a code to sum of XOR of all subarrays and the other steps required given the following:
Sum of XOR of all subarrays | Function to calculate the Sum of XOR of all subarrays.
variable to store the final Sum.
multiplier.
variable to store number of sub - arrays with odd number of elements with ith bits starting from the first element to the end of the array.
variable to check the status of the odd - even count while calculating c_odd.
loop to calculate initial value of c_odd.
loop to iterate through all the elements of the array and update Sum.
updating the multiplier.
returning the Sum.
Driver Code"
Solution in Python:
assistant
#Here is code to sum of XOR of all subarrays and the other steps required.
 def findXorSum ( arr , n ) :
	Sum = 0
	mul = 1
	for i in range ( 30 ) :
		c_odd = 0
		odd = 0
		for j in range ( n ) :
			if ( ( arr [ j ] & ( 1 << i ) ) > 0 ) :
				odd = ( ~ odd )
			if ( odd ) :
				c_odd += 1
		for j in range ( n ) :
			Sum += ( mul * c_odd )
			if ( ( arr [ j ] & ( 1 << i ) ) > 0 ) :
				c_odd = ( n - j - c_odd )
		mul *= 2
	return Sum
arr = [ 3 , 8 , 13 ]
n = len ( arr )
print ( findXorSum ( arr , n ) )