How does color hex values work? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

How does color hex values work?

Same as this ^.. i know how representing words and numbers in hex but how do you represent a color?

25th Aug 2017, 12:19 AM
Elad Goldenberg
Elad Goldenberg - avatar
5 Respuestas
+ 5
So I just tried learning this and it was confusing so this may not be entirely accurate but I'll try. So I'm guessing you know this part but just in case there are 16(base) values with 0-9 and A-F being 10-15 (0 1 2 3 4 5 6 7 8 9 A B C D E F). So with hex colour values you pair two hex values together for each colour, like FF0000 would be 255 for red and 0 for the other colours. The equation for converting each pair to a RGB value between 0-255 is like this: firstValueInPair * (16 ^ 1) = firstValue secondValueInPair * (16 ^ 0) = secondValue (which is just the original value anyway) total = firstValue + secondValue so for example the hex colour of 1c2a87 (1c-2a-87) (red, green, blue) would be worked out like this: 1 * (16 ^ 1) = 16 12(c) * (16 ^ 0) = 12 16 + 12 = 28 (red) 2 * (16 ^ 1) = 32 10(a) * (16 ^ 0) = 10 32 + 10 = 42 (green) 8 * (16 ^ 1) = 128 7 * (16 ^ 0) = 7 128 + 7 = 135 (blue) which makes 28,42,135 RGB that's the best I could do at explaining it, hope it makes sense.
25th Aug 2017, 1:13 AM
Enzo
Enzo - avatar
+ 4
Idk why you would use hex over rgb unless only hex was compatible for whatever reason or because it looks neater. For rgba from the small amount of research i did it looks like it was added to chrome (ver.52) with the expression #rrggbbaa where I believe its the same expression except the number from 255 -0 would be equal to 1-0 which can be calculated like lets say the hex value is 1c for alpha which is 28 after the equation you then could do 28/255 which would round off to .1 which would be the alpha value. That being said they removed the alpha from hex as it messed with how some of the code previously worked but I also read that its going to be possible in CSS4 so it wasn't a complete waste of time reading the first part :P. (I tried in chrome (latest version) and it didn't work so I'm assuming what I said is true)
25th Aug 2017, 2:08 AM
Enzo
Enzo - avatar
+ 2
Thank you all I learned a lot
25th Aug 2017, 2:09 AM
Elad Goldenberg
Elad Goldenberg - avatar
0
I understood it very well, it is kind of stupid as I think if the end result is explaining it in rgb... why use it anyway when you can use rgb first?... any way how would you determine RGBA into hex?
25th Aug 2017, 1:25 AM
Elad Goldenberg
Elad Goldenberg - avatar