In this article we’ll discuss about different number representation systems, where they are used and why they are useful. Briefly we’ll go through **decimal**, **binary**, **octal** and **hexadecimal** number representation.

#### Decimal (base 10)

The most common system for number representation is the **decimal**. Everybody is using it. It’s so common than most people must believe that is the only one. It’s used in finances, engineering and biology, almost everywhere we see and use numbers.

If someone is asking you to think at a number for sure you’ll think at a decimal number. If you think at a binary or hexadecimal one, you must have an extreme passion for arithmetic or software/programming.

As the name is saying the decimal number system is using **10** symbols/characters. In Latin language 10 is “decem” so decimal might be linked to the Latin word.

Decimal Symbols | |||||||||

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

As you can see there are 10 symbols from `0`

to `9`

. With these symbols we can construct all the numbers in the decimal system.

All the numbers in the decimal system can be constructed by using the above mentioned symbols (`0 … 9`

) multiplied with the power of 10. The power of ten gives us ones, tens, hundreds, thousands and so on.

\[10^k\] | … | \[10^5\] | \[10^4\] | \[10^3\] | \[10^2\] | \[10^1\] | \[10^0\] |

N | … | 100000 | 10000 | 1000 | 100 | 10 | 1 |

The example below breaks down the decimal number `67049`

into powers of 10 multiplied with numbers between `0`

and `9`

. This is just to show that any number in the decimal system can be decomposed into a sum of terms made of from the product of the power of 10 and the symbols `0 … 9`

.

67049 | |||||||

\[10^7\] | \[10^6\] | \[10^5\] | \[10^4\] | \[10^3\] | \[10^2\] | \[10^1\] | \[10^0\] |

0 | 0 | 0 | 6 | 7 | 0 | 4 | 9 |

\[ \begin{equation*} \begin{split} 67049 &= 6 \cdot 10^4 &+ 7 \cdot 10^3 &+ 0 \cdot 10^2 &+ 4 \cdot 10^1 &+ 9 \cdot 10^0 \\ &= 60000 &+ 7000 &+ 0 &+ 40 &+ 9 \end{split} \end{equation*} \] |

The same technique is going to be applied to the binary, octal and hexadecimal systems, being in fact a method of converting a number from decimal system in another format (base).

We can keep in mind these characteristics of the decimal numbers system:

- it’s using 10 symbols
- can be decomposed in factors containing powers of 10
- it’s the most common number representation system

#### Binary (base 2)

Let’s step into the geek side now.

Another number representation system is the **binary** one. As the name suggests and by analogy with the decimal system we can say that the binary system is using only 2 symbols/characters:

Binary Symbols | |

0 | 1 |

In the binary representation we only use `0`

(zeros) and `1`

(ones) to represent numbers.

The binary system is used wherever you want to store information in electronic format. All the computers that you know, intelligent devices, everything that has to do with electronics and microcontrollers use the binary system.

In electronics (digital) all the operations are done using two levels of voltage: high and low. Each level of voltage is assigned to a value/symbol: HIGH for 1 and LOW for 0. For a microcontroller which is supplied with +5V the `1`

(high) will be represented by +5 V and the `0`

(low) by 0 V.

Roughly we can say that the binary system is used because it can be translated in electronic signal.

All the decimal numbers we can think of can be represented into binary symbols. We do this by using a sum between terms of the power of 2 multiplied with 0 or 1.

\[2^k\] | … | \[2^7\] | \[2^6\] | \[2^5\] | \[2^4\] | \[2^3\] | \[2^2\] | \[2^1\] | \[2^0\] |

N | … | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

As example we’ll use the number `149`

(decimal representation) and transform it into binary representation. We could use any number but if it’s too big it would end up into a long string of zeros and ones.

149 | |||||||

\[2^7\] | \[2^6\] | \[2^5\] | \[2^4\] | \[2^3\] | \[2^2\] | \[2^1\] | \[2^0\] |

1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |

\[ \begin{equation*} \begin{split} 149 &= 1 \cdot 2^7 &+ 0 \cdot 2^6 &+ 0 \cdot 2^5 &+ 1 \cdot 2^4 &+ 0 \cdot 2^3 &+ 1 \cdot 2^2 &+ 0 \cdot 2^1 &+ 1 \cdot 2^0\\ &= 128 &+ 0 &+ 0 &+ 16 &+ 0 &+ 4 &+ 0 &+ 1 \end{split} \end{equation*} \] |

As you can see the decimal number `149`

is represented in binary system by a series of zeros and ones (`10010101`

). Usually to distinguish between a decimal or binary number we must specify the base to which we are referring to. The base is described as a subscript after the last character of the number

Example:

Decimal (base 10) | Binary (base 2) |

\[149_{10}\] | \[10010101_{2}\] |

By specifying the base of the number we eliminate the probability of confusion, because the same representation (e.g. 11) can mean different things for different bases.

\[11_{2} \neq 11_{10}\] |

Another way to avoid confusion is to use a special notation (prefix) for binary numbers. This is because `1100`

can represent eleven hundreds in decimal system or the decimal twelve represented in binary system. So if want to specify a binary number we use the prefix

. Example: **0b**`0b1100`

.

Briefly the characteristics of a binary system are:

- it’s using 2 symbols
- can be decomposed in factors containing powers of 2
- it’s used in computers, microcontrollers

#### Octal (base 8)

All the numbers in the **octal** system are represented using 8 symbols/characters, from `0`

to `7`

. The reason of using the octal system instead of the decimal one can be various. One of them is that instead of using our fingers for counting, we use the spaces between fingers.

Humans have 4 spaces between the fingers of one hand; in total we’ll have 8 spaces, for both hands. In this case it makes sense to use an octal number representation system instead of a decimal one. The drawback is that higher numbers will require more characters compared to the decimal one.

Octal Symbols | |||||||

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |

To transform a decimal represented number into an octal system we split it into terms containing the power of 8:

\[8^k\] | … | \[8^5\] | \[8^4\] | \[8^3\] | \[8^2\] | \[8^1\] | \[8^0\] |

N | … | 32768 | 4096 | 512 | 64 | 8 | 1 |

As an example we are going to represent the decimal number `67049`

in octal base:

67049 | |||||

\[8^5\] | \[8^4\] | \[8^3\] | \[8^2\] | \[8^1\] | \[8^0\] |

2 | 0 | 2 | 7 | 5 | 1 |

\[ \begin{equation*} \begin{split} 67049 &= 2 \cdot 8^5 &+ 0 \cdot 8^4 &+ 2 \cdot 8^3 &+ 7 \cdot 8^2 &+ 5 \cdot 8^1 &+ 1 \cdot 8^0 \\ &= 65535 &+ 0 &+ 1024 &+ 448 &+ 40 &+ 1 \end{split} \end{equation*} \] |

#### Hexadecimal (base 16)

The **hexadecimal** number representation system is using 16 symbols/characters to define numbers. It’s used in computer science mostly because can represent bigger decimal numbers with fewer characters.

Hexadecimal Symbols | |||||||||||||||

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |

Compared with decimal system it’s also using numeric symbols from 0 to 9. Additionally it’s using alphanumeric characters from A to F for values between 10 and 15.

\[16^k\] | … | \[16^5\] | \[16^4\] | \[16^3\] | \[16^2\] | \[16^1\] | \[16^0\] |

N | … | 1048576 | 65535 | 4096 | 256 | 16 | 1 |

To represent a decimal number in hexadecimal format we split the decimal number into a sum of terms. Each term is a product between a hexadecimal symbol and a power of 16.

67049 | ||||

\[16^4\] | \[16^3\] | \[16^2\] | \[16^1\] | \[16^0\] |

1 | 0 | 5 | E | 9 |

\[ \begin{equation*} \begin{split} 67049 &= 1 \cdot 16^4 &+ 0 \cdot 16^3 &+ 5 \cdot 16^2 &+ E \cdot 16^1 &+ 9 \cdot 16^0\\ &= 65536 &+ 0 &+ 1280 &+ 224 &+ 9 \end{split} \end{equation*} \] |

The representation of the decimal number `67049`

in hexadecimal format is `105E9`

. Similar to the binary system a common practice is to use the prefix “`0x`

” in order to distinguish from the decimal notation. Example: `0x105E9`

.

Briefly the characteristics of a hexadecimal number representation system are:

- it’s using 16 symbols
- can be decomposed in factors containing powers of 16
- it’s used in computers, microcontrollers

The table below summaries the characteristics of the above mentioned number representation systems.

System | Number of Symbols | Symbols | Prefix | Example |

Decimal | 10 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | None | 147 |

Binary | 2 | 0, 1 | 0b | 0b10010011 |

Hexadecimal | 16 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,B, C, D, E, F | 0x | 0x93 |

Both the octal and hexadecimal number representation systems are linked to the computer system, mainly with the kind of processors and microcontrollers. For example, if the microprocessor is using 8 bit data then the octal system is suitable to interface data. If the microprocessor is on 16 bits then the hexadecimal system is appropriate to represent data.