See all glossary terms

Hexadecimal

We are used to count in a decimal system.
This is a system where the amount of unique numerals is ten, starting at 0 until 9. To count more than the tenth number (which is 9), we need to use 2 or more of the existing numerals.
In decimal, the digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
We call this a system with a "base 10"
To reach the number after 9, we need to associate two previous numerals: 0, and 1: 10, 11, ..., 42, ...
Hexadecimal is a "base 16" system, where the digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
DecimalHexadecimal
00
11
22
33
44
55
66
77
88
99
10A
11B
12C
13D
14E
15F
If we want to represent 16 in decimal, we need to add two more digits: 1, and 0. It's very unintuitive! But you get used to it.
DecimalHexadecimal
1610
1711
1812
1913
2014
......
160A0
161A1
176B0

How to get the decimal number from a hexadecimal number?

  1. Split the number in digits
  2. For each digit, convert it do decimal (A to 10, B to 11, C to 12, and so on)
  3. Counting from the right, multiply each digit by the 16 raised to the power of its position. So the first digit is 16^0, the second digit is 16^1, and so on.
  4. Add all the products together
Let's take C2:
digitpower 16
C12 X 16^1=192
22 X 16^0=2
total=194
Let's take FF:
digitpower 16
F15 X 16^1=15
F15 X 16^0=240
total=255

What does any of this has to do with colors?

In regular programming, hexadecimal is most often encountered to encode colors.
For example
  • #FF0000 is red.
  • #00FF00 is green.
  • #0000FF is blue.
The format is #RRGGBB, where RR, GG, and BB are hexadecimal values for the red, green, and blue channels, respectively.
This is because the hexadecimal color encoding takes two digits to represent each color channel: in the first example,FF is the amount of red in the color, and 00 is the amount of green in the color. FF is equal to 255, so that is equivalent to writing rgb(255, 0, 0).
Some hexadecimal notations add two digits to represent alpha: #RRGGBBAA, where 00 is completely transparent, and FF is completely opaque.
Finally, in some languages, it is accepted to use the #RGB format, forgeting the 0 for small numbers.