How a hex color becomes RGB
A hex code is three numbers written in base 16, one for each of red, green and blue. Base 16 uses the digits 0 to 9 and then a to f for the values 10 to 15, so two digits can hold any number from 0 to 255. To read a pair, multiply the first digit by 16 and add the second.
In #c5ec43 the red pair is c5: c is 12, so 12 × 16 + 5 = 197. The green pair ec is 14 × 16 + 12 = 236, and the blue pair 43 is 4 × 16 + 3 = 67. The color is rgb(197, 236, 67). Some codes you will recognise:
#000000is rgb(0, 0, 0), black.#ffffffis rgb(255, 255, 255), white.#ff0000is rgb(255, 0, 0), pure red.#808080is rgb(128, 128, 128), a middle grey.
A three digit code is shorthand that doubles each digit: #fa0 means #ffaa00, which is rgb(255, 170, 0).
Where you need RGB instead of hex
CSS accepts both, but RGB is the form to use when you want transparency in older syntax (rgba()), when a design tool or API asks for separate red, green and blue fields, or when you need to calculate with the channels, for example to blend two colors.
Graphics code often wants fractions instead of 0 to 255. Divide each channel by 255: 197 becomes 0.7725, 236 becomes 0.9255 and 67 becomes 0.2627. This page shows those numbers, ready for shaders, Three.js, Unity and similar tools. On Android, Color.rgb(197, 236, 67) takes the 0 to 255 values directly.
Hex codes with transparency
An 8 digit code adds a fourth pair for opacity, where 00 is fully see-through and ff is solid. Divide the pair's value by 255 to get the alpha for rgba(). Common values, rounded to the nearest step out of 256:
ffis 100%,e6is 90%,ccis 80%,b3is 70%,99is 60%.80is 50%,66is 40%,4dis 30%,33is 20%,1ais 10%,00is 0%.
Type an 8 digit code, for example c5ec4380, and the result shows rgba(197, 236, 67, 0.502).