Python - Hex

From Torben's Wiki
Revision as of 08:57, 15 June 2009 by Torben (talk | contribs) (Created page with 'Category:Python 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 …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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