Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Hex decimal tutorial (Easy)

Intro 
Ever wondered how computers can read that #8b0000 is the color dark red? 
And why is hex a based 16 system? 
Today I want to share my knowledge to make this clearer to you. 
 
RGB 
The post you are reading now is made of tiny pixels on your screen (1920x1080) in my case. 
Every pixel has a red, green, and blue light (RGB). These colors are added together to produce what your eyes see as 1 color.  
Hex 
So now we know what RGB stands for and what function it has, lets focus on what Hex does. 
Hex is a 6-digit code (#123456) with 3 different parts. 
1 = 12 (Red) 
2 = 34 (Green) 
3 = 56 (Blue) 

Hex tells the computer how much to use of each light from the RGB. 
The 16-based system 
0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F 
Hex has a 16-based system so that more than 99 values can be held in 2 digits. Because of this the computer can read more than 16 million combinations.
A stands for 10 
B stands for 11 
C stands for 12 
D stands for 13 
E stands for 14 
F stands for 15 
0 to F (15) = 16 
Every digit needs to be multiplied to 16 and be squared to the power of its place. 

Example Hexdecimal to decimal 
E6A8 
E= 14×16(3) <- = 57344 
6= 6×16(2) <- (2) stands for square) = 1536 
A= 10×16(1) = 160 
8= 8×16 (0) = 8 
57344+1536+160+8 = 59048(10) <- (10) stands for square 

Extra Hexdecimal to binary 
In case you are interested how to covert hex decimal to binary (10011010)  
E6 = 
E= 14 
6 = 6 
Take the standard table like explained in my previous tutorial of binary code
(128 64 32 16 8 4 2 1) 
We only need 8 4 2 and 1 for both numbers (14 and 6) because it doesn't go higher then 14. 
14= 1110 
6= 0110 
-----------+ 
11100110 
 
Thank you for reading. I hope you learned something today. 
I would like to see your feedback on this tutorial. 
 
Greetings, 
Cool, never really though of it. Nice spreading information!!!
few things wrong.

1. you're referring to hexadecimal as hex. that's not really an issue, most people do it, but a true hex system would have a base6 system rather than base16. make sure this is clear.
as an extra definition you can just take apart the word. you have hex (latin for 6 is sex, modern english translates as hex) and you also have dec (latin for 10 is decem) so add them up and you get hexadec, or 6+10, or 16.

2. hex is not necessarily a 6 digit code, it varies greatly for the specific application that hexadecimal is used for. a byte of data will only have two digits, a memory address (assuming 32bit memory addressing) will have 8 digits, 64 bit will have 16, and in your case, rgb data (3 bytes) will have six digits. however this isn't always the case either because css rgb values can be three digit as well, ie. #fff will still translate to #ffffff, but it's just doubling each digit. 2, 4, 5 digit rgb values won't translate properly and will return an invalid property.

3. pixels don't always use an rgb scheme, some tvs at stores around me use rgby schemes, adding a yellow value to make yellow colors more prominent, as often they can seem muddy on screens. i dont know if this trend died or not, but it's just something to account for.
humble rubyist in a world of pythonistas


Possibly Related Threads...
Thread / Author Replies Views Last Post
by ernestmillerJul 15, 2017 04:47 AM 0 112 Jul 15, 2017 04:47 AM
Last Post: ernestmiller
by 'CynicalDec 14, 2016 04:32 PM 61 3,199 Dec 14, 2016 04:32 PM
Last Post: VirtualMon3y
by in_the_endOct 4, 2011 01:49 PM 8 104 Oct 4, 2011 01:49 PM
Last Post: OnkUnit