Python - Hex

From Torben's Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

XOR

xor(a, b) # Same as a ^ b.

char <-> int

i  = ord (c)
c = chr(i)
def dec2hex(n):
  # n is integer!
  return "%X" % n

def hex2dec(s):
  # s is string!
  return int(s, 16)

print dec2hex(255) # FF
print hex2dec('FF') # 255
print hex(255) # 0xff
print hex2dec('0xff') # 255