Key takeaways
- Split the code into pairs and convert each pair to a number from 0 to 255.
- Multiply the first digit by 16 and add the second.
- To go back, divide each number by 16 for the digit pair.
Converting hex to RGB means turning each pair of hex digits into a number from 0 to 255.
Worked example
Take #1E90FF (dodgerblue). Split it into 1E, 90 and FF. Convert each pair: 1E is 30, 90 is 144 and FF is 255. The RGB value is rgb(30, 144, 255).
The rule
Multiply the first digit by 16 and add the second. For 1E, that is 1 × 16 + 14 = 30, since E stands for 14.
Going back
To go from RGB to hex, divide each number by 16. The whole part is the first digit and the remainder is the second. For 144, that is 9 with a remainder of 0, so the pair is 90.
Skip the math with the converter tool, which also gives HSL, HSV and CMYK.