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
In decimal, the digits are
We call this a system with a "base 10"
To reach the number after
*Hexadecimal* is a "base 16" system, where the digits are

If we want to represent 16 in decimal, we need to add two more digits:

## How to get the decimal number from a hexadecimal number?

Let's take

Let's take

## What does any of this has to do with colors?

In regular programming, hexadecimal is most often encountered to encode colors.
For example
The format is
This is because the hexadecimal color encoding takes two digits to represent each color channel: in the first example,
Some hexadecimal notations add two digits to represent alpha:
Finally, in some languages, it is accepted to use the

`0`

until `9`

. To count more than the tenth number (which is 9), we need to use 2 or more of the existing numerals.`0`

, `1`

, `2`

, `3`

, `4`

, `5`

, `6`

, `7`

, `8`

, `9`

.`9`

, we need to associate two previous numerals: `0`

, and `1`

: `10`

, `11`

, ..., `42`

, ...`0`

, `1`

, `2`

, `3`

, `4`

, `5`

, `6`

, `7`

, `8`

, `9`

, `A`

, `B`

, `C`

, `D`

, `E`

, `F`

.Decimal | Hexadecimal |
---|---|

`0` | `0` |

`1` | `1` |

`2` | `2` |

`3` | `3` |

`4` | `4` |

`5` | `5` |

`6` | `6` |

`7` | `7` |

`8` | `8` |

`9` | `9` |

`10` | `A` |

`11` | `B` |

`12` | `C` |

`13` | `D` |

`14` | `E` |

`15` | `F` |

`1`

, and `0`

. It's very unintuitive! But you get used to it.Decimal | Hexadecimal |
---|---|

`16` | `10` |

`17` | `11` |

`18` | `12` |

`19` | `13` |

`20` | `14` |

`...` | `...` |

`160` | `A0` |

`161` | `A1` |

`176` | `B0` |

- Split the number in digits
- For each digit, convert it do decimal (
`A`

to`10`

,`B`

to`11`

,`C`

to`12`

, and so on) - 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.
- Add all the products together

`C2`

:digit | power 16 | ||
---|---|---|---|

C | 12 X 16^1 | = | 192 |

2 | 2 X 16^0 | = | 2 |

total | = | 194 |

`FF`

:digit | power 16 | ||
---|---|---|---|

F | 15 X 16^1 | = | 15 |

F | 15 X 16^0 | = | 240 |

total | = | 255 |

`#FF0000`

is red.`#00FF00`

is green.`#0000FF`

is blue.

`#RRGGBB`

, where `RR`

, `GG`

, and `BB`

are hexadecimal values for the red, green, and blue channels, respectively.`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)`

.`#RRGGBBAA`

, where `00`

is completely transparent, and `FF`

is completely opaque.`#RGB`

format, forgeting the `0`

for small numbers.