human
Convert Decimal To Hexa | Function to convert decimal no . to hexadecimal number.
map for decimal to hexa , 0 - 9 are straightforward , alphabets a - f used for 10 to 15..
string to be returned.
check if num is 0 and directly return "0".
if num > 0 , use normal technique as discussed in other post.
if num < 0 , we need to use the elaborated trick above , lets see this.
store num in a u_int , size of u_it is greater , it will be positive since msb is 0.
use the same remainder technique ..
Driver Code"
How can the above be solved in Python?
 ... What is a code to convert Decimal To Hexa and the other steps required?
assistant
#Here is code to convert Decimal To Hexa and the other steps required.
 def Hex ( num ) :
	m = dict . fromkeys ( range ( 16 ) , 0 ) ;
	digit = ord ( '0' ) ;
	c = ord ( ' a ' ) ;
	for i in range ( 16 ) :
		if ( i < 10 ) :
			m [ i ] = chr ( digit ) ;
			digit += 1 ;
		else :
			m [ i ] = chr ( c ) ;
			c += 1
	res = " " ;
	if ( not num ) :
		return "0" ;
	if ( num > 0 ) :
		while ( num ) :
			res = m [ num % 16 ] + res ;
			num //= 16 ;
	else :
		n = num + 2 ** 32 ;
		while ( n ) :
			res = m [ n % 16 ] + res ;
			n //= 16 ;
	return res ;
if __name__ == " _ _ main _ _ " :
	x = 134 ; y = - 1 ; z = - 234 ;
	print ( " Hexa ▁ representation ▁ for " ) ;
	print ( x , " is " , Hex ( x ) ) ;
	print ( y , " is " , Hex ( y ) ) ;
	print ( z , " is " , Hex ( z ) ) ;