Created
October 29, 2012 01:55
-
-
Save zealoushacker/3970953 to your computer and use it in GitHub Desktop.
Explanation of hex colors.
This file contains hidden or 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
HTML colors are broken into 3 components: | |
R: Red | |
G: Green | |
B: Blue | |
These 3 components may be represented in hexadecimal. | |
A hexadecimal representation of the 3 components is called a triplet, or group of 3 numbers. | |
R G B R G B | |
Black: #000000 0x00, 0x00, 0x00 | |
Red: #FF0000 0xFF, 0x00, 0x00 | |
Green: #00FF00 0x00, 0xFF, 0x00 | |
Blue: #0000FF 0x00, 0x00, 0xFF | |
White: #FFFFFF 0xFF, 0xFF, 0xFF | |
In decimal, the digits are 0-9. | |
In hexadecimal, the digits are 0-F, which is equivalent to 0-15 in decimal. | |
In decimal, the rightmost digit are the ones. | |
Likewise in hexadecimal. | |
In decimal, the 2nd digit from the right are the tens. | |
In hexadecimal, however, these are the 16s. | |
Each component is a two-digit hexadecimal value. | |
0x00 is equivalent to 0: | |
0 * 1 = 0 | |
+ 0 * 16 = 0 | |
------------- | |
= 0 | |
0xFF is equivalent to 255: | |
15 * 16 = 240 | |
+ 15 * 1 = 15 | |
--------------- | |
= 255 | |
From this simple conversion, we can easily figure out the total number of possible colors. | |
The digits are the powers of 16, with the least significant on the right, and most significant digit on the left. | |
16^5 = 1048576s 16^4 = 65536s 16^3 = 4096s 16^2 = 256s 16^1 = 16s 16^0 = 1s | |
F F F F F F | |
15 * 1048576 = 15728640 | |
15 * 65536 = 983040 | |
15 * 4096 = 61440 | |
15 * 256 = 3840 | |
15 * 16 = 240 | |
+ 15 * 1 = 15 | |
--------------------------- | |
= 16777215 color possibilities |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also watch this free lecture on Coursera by Nick Parlante from Google: https://class.coursera.org/cs101-2012-selfservice/lecture/2