Advertisement
here2share

# RGB2Hex_and_Hex2RGB.py

Jun 7th, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. # RGB2Hex_and_Hex2RGB.py
  2.  
  3. def hex_to_rgb(value):
  4.     value = value[1:]
  5.     lv = len(value)
  6.     return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
  7.  
  8. def rgb_to_hex(rgb):
  9.     return '#%02x%02x%02x' % rgb
  10.  
  11. print hex_to_rgb("#ffffff")             # (255, 255, 255)
  12. print rgb_to_hex((255, 255, 255))       # '#ffffff'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement