Last active
August 29, 2015 14:24
-
-
Save gpratt/3a23dd807afa932800a0 to your computer and use it in GitHub Desktop.
flip_hex_vaule
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
def flip_hex_value(hex_value): | |
has = "" | |
if hex_value.startswith("#"): | |
has = "#" | |
hex_value = hex_value.lstrip("#") | |
bits = bin(int(hex_value, 16))[2:] | |
flipped = "".join(["1" if bool(int(bit)) ^ True else "0" for bit in bits]) | |
return has + "{0:0>{width}x}".format(int(flipped, 2), width=len(hex_value)) | |
flip_hex_value("#262626") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment