I have integer number in ex. 16 and i am trying to convert this number to a hex number. I tried to achieve this by using hex function but whenever you provide a integer numb
Using the string formatters (new first, then old):
>>> '{:x}'.format( 12345678 )
'bc614e'
>>> '%x' % ( 12345678 )
'bc614e'
def add_hex2(hex1, hex2):
"""add two hexadecimal string values and return as such"""
return hex(int(hex1, 16) + int(hex2, 16))
print add_hex2('0xff', '0xff') # 0x1fe