human
Program to convert a Binary Number to Hexa | Function to convert BCD to hexadecimal.
Iterating through the bits backwards.
Computing the hexadecimal number formed so far and storing it in a vector ..
Reinitializing all variables for next group ..
Printing the hexadecimal number formed so far ..
Driver Code.
Function Call"
How can the above be solved in Python?
 Write me a code to program to convert a Binary Number to Hexa and the other steps required?
assistant
#Here is code to program to convert a Binary Number to Hexa and the other steps required.
 def bcdToHexaDecimal ( s ) :
	len1 = len ( s )
	check = 0
	num = 0
	sum = 0
	mul = 1
	ans = [ ]
	i = len1 - 1
	while ( i >= 0 ) :
		sum += ( ord ( s [ i ] ) - ord ( '0' ) ) * mul
		mul *= 2
		check += 1
		if ( check == 4 or i == 0 ) :
			if ( sum <= 9 ) :
				ans . append ( chr ( sum + ord ( '0' ) ) )
			else :
				ans . append ( chr ( sum + 55 ) ) ;
			check = 0
			sum = 0
			mul = 1
		i -= 1
	len1 = len ( ans )
	i = len1 - 1
	while ( i >= 0 ) :
		print ( ans [ i ] , end = " " )
		i -= 1
if __name__ == ' _ _ main _ _ ' :
	s = "100000101111"
	bcdToHexaDecimal ( s )