human
Check if the binary representation of a number has equal number of 0 s and 1 s in blocks | Function to convert decimal to binary.
Count same bits in last block.
If n is 0 or it has all 1 s , then it is not considered to have equal number of 0 s and 1 s in blocks ..
Count same bits in all remaining blocks ..
Driver Code"
Solution in Python:
 Give me a code to check if the binary representation of a number has equal number of 0 s and 1 s in blocks and the other steps required?
assistant
#Here is code to check if the binary representation of a number has equal number of 0 s and 1 s in blocks and the other steps required.
 def isEqualBlock ( n ) :
	first_bit = n % 2
	first_count = 1
	n = n // 2
	while n % 2 == first_bit and n > 0 :
		n = n // 2
		first_count += 1
	if n == 0 :
		return False
	while n > 0 :
		first_bit = n % 2
		curr_count = 1
		n = n // 2
		while n % 2 == first_bit :
			n = n // 2
			curr_count += 1
		if curr_count != first_count :
			return False
	return True
if __name__ == " _ _ main _ _ " :
	n = 51
	if isEqualBlock ( n ) :
		print ( " Yes " )
	else :
		print ( " No " )