human
XOR of two numbers after making length of their binary representations equal | Function to count the number of bits in binary representation of an integer.
initialize count.
count till n is non zero.
right shift by 1 i . e , divide by 2.
Function to calculate the xor of two numbers by adding trailing zeros to the number having less number of bits in its binary representation ..
stores the minimum and maximum.
left shift if the number of bits are less in binary representation.
Driver Code"
Solution in Python:
assistant
#Here is code to xOR of two numbers after making length of their binary representations equal and the other steps required.
 def count ( n ) :
	c = 0
	while ( n != 0 ) :
		c += 1
		n = n >> 1
	return c
def XOR ( a , b ) :
	c = min ( a , b )
	d = max ( a , b )
	if ( count ( c ) < count ( d ) ) :
		c = c << ( count ( d ) - count ( c ) )
	return ( c ^ d )
a = 13 ; b = 5
print ( XOR ( a , b ) )