Created
September 9, 2014 09:31
-
-
Save ayushgoel/c47816881c61038668ba to your computer and use it in GitHub Desktop.
Convert Hex value for colour to decimal (cfcfcf) -> (207 207 207)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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