Hexadecimal

2025/12/27

Type
Learning Resource
Format
Glossary Article
Version
General
Subject Tags
Code
Assets
All else
Copyright 2016-2026, GDQuest
Created
2026/02/16
Updated
2025/12/27

Hexadecimal

We are used to counting in a decimal system.

This is a system where the amount of unique numerals is ten, starting at 0 and going up to 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.

| 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 |

If we want to represent 16 in hexadecimal, we need to use two digits: 1 and 0. It's very unintuitive at first, but you get used to it.

| Decimal | Hexadecimal | |--------:|:------------| | 16 | 10 | | 17 | 11 | | 18 | 12 | | 19 | 13 | | 20 | 14 | | ... | ... | | 160 | A0 | | 161 | A1 | | 176 | B0 |

How to get the decimal number from a hexadecimal number?

  1. Split the number into digits
  2. For each digit, convert it to decimal (A to 10, B to 11, C to 12, and so on)
  3. Counting from the right, multiply each digit by 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:

| digit | power 16 | | | |------:|----------:|--|:----| | C | 12 X 16^1 |= | 192 | | 2 | 2 X 16^0 |= | 2 | | | total |= | 194 |

Let's take FF:

| digit | power 16 | | | |------:|----------:|--|:----| | F | 15 X 16^1 |= | 240 | | F | 15 X 16^0 |= | 15 | | | total |= | 255 |

What does any of this have to do with colors?

In regular programming, hexadecimal is most often encountered to encode colors.

For example:

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, omitting the 0 for small numbers.

Become an Indie Gamedev with GDQuest!

Don't stop here. Step-by-step tutorials are fun but they only take you so far.

Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.

Nathan

Founder and teacher at GDQuest
  • Starter Kit
  • Learn Gamedev from Zero
Check out GDSchool

You're welcome in our little community

Get help from peers and pros on GDQuest's Discord server!

20,000 membersJoin Server

Contribute to GDQuest's Free Library

There are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!