# Binary, Decimal, Hexadecimal and Octal Systems

So far we have talked about how to represent numbers, positional notation, and how with it we can represent numbers in any base.

Among the infinite bases we could define, there are some that are used more than others. These are the decimal system, the binary system, octal, and hexadecimal.

Each has its own characteristics and applications in the field of computing and programming. So let’s talk a little about each of them 👇.

## Decimal System

The decimal system is the most widely used numerical system in everyday life. It is the one we use every day. As you know, it consists of ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

Each position in a decimal number represents a power of ten. For example, the decimal number 123 represents

``1 * 10² + 2 * 10¹ + 3 * 10⁰``

Which is equal to 123 in decimal (oh, what a surprise! 😆)

Although it is intuitive for humans, simply because we are used to it, at the computational level “it fits poorly, leaning towards terrible”.

Therefore, although we will continuously use it in our programs, generally it will have to be translated so that it can be managed by the computer.

## Binary System

The binary system is the fundamental numerical system in digital electronics and computing. This is because it is easier to build digital machines, and these have several advantages over other types of machines *(besides, the binary system is the main focus of this course 😊).

The binary system is base 2, and therefore is composed of only two symbols. We could have chosen any symbol, but for simplicity, we call them `0` and `1`.

Each position in a binary number represents a power of two. For example, the binary number `1011` represents

``1 * 2³ + 0 * 2² + 1 * 2¹ + 1 * 2⁰``

Which is equal to 11 in decimal.

## Octal System

The octal system is another numerical system used in computing, although it is less common and used compared to binary, decimal, and hexadecimal.

This system consists of eight symbols, which again for convenience we will use 0, 1, 2, 3, 4, 5, 6, and 7.

Each position in an octal number represents a power of eight. For example, the octal number 53 represents

``5 * 8¹ + 3 * 8⁰,``

Which is equal to 43 in decimal.

It is not as important as the others in this entry, so we won’t spend much more time on it. But just in case you ever come across it, there it is.

The hexadecimal system is an extension of the decimal system that uses sixteen symbols. For simplicity, we will continue using the symbols from 0 to 9, but… oh, oh… we have run short of symbols. So we will expand it by “borrowing” the letters A to F.

That is, generally the set of symbols we will use in hexadecimal will be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, which correspond to the numbers 0 to 15 in decimal.

Each position in a hexadecimal number represents a power of sixteen. For example, the hexadecimal number 1A3 represents

``1 * 16² + 10 * 16¹ + 3 * 16⁰``

Which is equal to 419 in decimal.

Why did we invent such an aberration of nature? Because it is a very convenient way to work with binary numbers. In programming, it is commonly used to represent memory addresses, colors on the screen, and hexadecimal values of bytes.

Let’s remember that the smaller your base, the longer the number you have to use. The hexadecimal format allows you to work with much more compact numbers than the binary system.

Since, unlike the decimal system, 16 is a power of 2, the conversion between binary and hexadecimal is very fast. Every 4 digits in binary correspond to one digit in hexadecimal.

## Comparison between systems

Let’s see the first sixteen numbers, encoded in decimal, binary, octal, and hexadecimal.

0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F

Interesting things to see:

• Decimal is the one we are used to seeing
• Binary, well, binary 😅
• Octal is a disaster (if your teacher gets too heavy with octal, tell them on my behalf that it’s something useless… octal, that is, not your teacher 😉).
• Hexadecimal is difficult at first because you have 6 letters (A … F), but it has the advantage of converting very easily with binary.
• On the other hand, decimal, starting from 9 has gone to 2 digits. Therefore, the conversion is much more difficult from binary to decimal than from binary to hexadecimal.