The math behind HEX to RGB
Read more
A HEX color is three base-16 numbers wearing a # prefix. Base-16 uses the digits 0-9 plus a-f, and two of those digits cover exactly 0 to 255, the same range as an RGB channel. The first pair is red, the second green, the third blue. To convert a pair by hand, multiply the first digit's value by 16 and add the second: d3 is 13 × 16 + 3 = 211.
Going the other way, divide the channel by 16: the quotient is the first digit and the remainder is the second, so 52 becomes 3 and 4, written 34. Because the two systems map one-to-one, no precision is lost in either direction. That is why this converter is exact rather than approximate, and why you can round-trip a color between formats as many times as you like.