Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Example 7: Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.
- print "%02X%02X%02X" % (255, 0, 128)
- def toHex(i):
- def _toHex(i):
- if i <= 15:
- if i <=9:
- return str(i)
- return chr(ord("A") + (i-10))
- return _toHex(i >> 4) + _toHex(i%16)
- res = _toHex(i)
- if len(res) == 1:
- res = "0" + res
- return res
- print "".join((toHex(255), toHex(0), toHex(128)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement