Skip to content

Instantly share code, notes, and snippets.

@DarthJahus
Created November 22, 2018 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarthJahus/2b29b395357961ffe58f3fcb388e9614 to your computer and use it in GitHub Desktop.
Save DarthJahus/2b29b395357961ffe58f3fcb388e9614 to your computer and use it in GitHub Desktop.
Simple Python script to convert hexadecimal color codes to RGB
"""
Simple Python script to convert hexadecimal color codes to RGB
Jahus, 2018-11-21
"""
while True:
try:
print("Hex?")
s = input()
s = s.replace('#', '').replace('0x', '')
h = int(s, 16)
b = h & 0xFF
g = (h & 0xFF00) >> 8
r = (h & 0xFF0000) >> 16
print("R: %s\nG: %s\nB: %s" % (r, g, b))
except KeyboardInterrupt:
exit()
except:
print("Wrong format. Try again.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment