CCalclabhub

Color

Hex to RGB

Each pair of hex digits is a base-sixteen number from 0 to 255, in red, green and blue order.

Last updated

The Formula

R = 0xRR, G = 0xGG, B = 0xBB

Each pair of hex digits is a base-sixteen number from 0 to 255, in red, green and blue order.

SymbolMeaning
h1High nibble
h2Low nibble

What Each Symbol Means

h1digit

High nibble

The first hex digit of the pair, worth sixteen times its value.

h2digit

Low nibble

The second hex digit of the pair, worth its face value.

See It Worked With Real Numbers

A formula on its own does not tell you which number goes where. The how to convert colors page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.

Where This Formula Appears

This equation is the working core of How To Convert Colors, filed under Unit Conversion. Every number the guide produces comes from substituting into this one line.

Common Questions

What is the formula for Hex to RGB?

The formula for Hex to RGB is R = 0xRR, G = 0xGG, B = 0xBB. Each pair of hex digits is a base-sixteen number from 0 to 255, in red, green and blue order.

What units should I use with Hex to RGB?

Substitute h1 in digit, h2 in digit. Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.

What is a common mistake when using Hex to RGB?

Swapping the channel order. Hex is red, green, blue in that order. Writing it as blue, green, red produces a plausible but wrong colour.