Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. ## Example 7: Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.
  2. print "%02X%02X%02X" % (255, 0, 128)
  3. def toHex(i):
  4. def _toHex(i):
  5. if i <= 15:
  6. if i <=9:
  7. return str(i)
  8. return chr(ord("A") + (i-10))
  9. return _toHex(i >> 4) + _toHex(i%16)
  10. res = _toHex(i)
  11. if len(res) == 1:
  12. res = "0" + res
  13. return res
  14. print "".join((toHex(255), toHex(0), toHex(128)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement