Skip to content

Instantly share code, notes, and snippets.

@ayushgoel
Created September 9, 2014 09:31
Show Gist options
  • Save ayushgoel/c47816881c61038668ba to your computer and use it in GitHub Desktop.
Save ayushgoel/c47816881c61038668ba to your computer and use it in GitHub Desktop.
Convert Hex value for colour to decimal (cfcfcf) -> (207 207 207)
#! /usr/bin/python
import sys
def colorForHex(x):
if len(x) != 6:
return "Poorly formatted HEX", x
try:
r = int(x[:2], 16)
g = int(x[2:4], 16)
b = int(x[4:], 16)
return "{0} -> {1} {2} {3}".format(x, r, g, b)
except ValueError:
return "Couldn't convert number", x
if __name__ == '__main__':
hexValues = sys.argv[1:]
for i in hexValues:
print colorForHex(i)
print "Thank you!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment