Number systems (binary, octal, decimal, hexadecimal)

# Number systems

Before we can explain some specific number systems, we need to know what a number system is. Simply put, a number system is a way to represent numbers.

We can classify number systems by type of notation as to whether they use positional notation (also known as place-value notation), and make further categorization by radix or base.

### 1. Non-Positional Number System

To explain non-positional number system, we will take Roman numerals as an example. In the table below, you can find decimal values for the basic symbols in the Roman number system. You may ask is there some pattern to form all of the other symbols? The answer is yes.

• When a symbol with a smaller value is placed after a symbol having an equal or larger value, the values are added. Examples are shown in the table below. • When a symbol with a smaller value is placed before a symbol having a larger value, the smaller value is subtracted from the larger one. Examples are shown in the table below. ### 2. Positional Number System

A positional number system allows the expansion of the original set of symbols so that they can be used to represent any arbitrarily large (or small) value. A number can be represented differently in different systems.
For example, the two numbers $(2A)_{16}$ and $(52)_{8}$ both refer to the same quantity, $(42)_{10}$.

The number system we are using every day is called the decimal number system or a number system with a base ten. As you can see from the name of the number system, the base determines the whole system.

Decimal number system has a base 10 because we are working with 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and every other larger number can be constructed from these 10 digits. In other words, we use the same set of symbols but assign a different value to the symbol based on its position within the number.

The position of the symbol with respect to other symbols in the number allows an individual symbol to represent greater (or lesser) values. That also means that  each digit is multiplied by an appropriate power of 10 depending on its position in the number.

For example:

$342=3 \cdot 10^{2}+4 \cdot 10^{1}+2 \cdot 10^{0}$

$= 3 \cdot 100+4 \cdot 10+2 \cdot 1$

$=300 + 40 + 2$

In this lesson we won’t be explaining decimal system in details as there are a lot of lessons on the page dedicated to it.

Apart from decimal number system, there are a lot of other number systems. We will mention just three of them as they are the most used number systems after decimal. These are: binary number system, octal number system and hexadecimal number system. We will give a short explanation on each of them and learn how to transform numbers from one system to another.

#### 2.1. Binary Number System

The binary number system contains two unique numerals (0 and 1). This system is thus a base 2 number system. The relative magnitudes of the symbols are 0 < 1.  The symbols in this system are often referred to as binary digits or just bits. Binary number system is a positional number system. Later we will see that, for example, $1010_{2} \neq 1100_{2}$.

#### 2.2. Octal Number System

The octal number system contains 8 unique numerals (0, 1, 2, 3, 4, 5, 6, 7). This system is thus a base 8 number system. The relative magnitudes of the symbols are 0 < 1 < 2 < 3 < 4 < 5 < 6 < 7. Octal number system is another example of positional number systems.

The hexadecimal number system contains 16 unique numerals.  Since there are only 10 Arabic numerals in the decimal system, we need to use other symbols to represent the remaining 6 numerals. We use the alphabetic
characters A–F in order to expand the system to 16 numerals. The 16 numerals in the hexadecimal system are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The relative magnitudes of the symbols are
0 < 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < A < B < C < D < E < F.
Hexadecimal number system is a positional number system, too.

### 3. Base Conversion

Each digit position in a “base b” number represents a power of $b$. So, when we write a “base b” number, each “base b” digit is multiplied by an appropriate power of $b$ based on the position in the number.

#### 3.1. Converting to Decimal

Converting a number from any number system to a decimal number is quite easy. We know that the value of each digit within a number is based on the individual digit value and the digit’s position. We’ve learned that when learning about decimal numbers. Using that rule, we can convert a number from any number system to a decimal number.

Let’s see a general example:

Imagine we have a number $d_{2}d_{1}d_{0}.d_{-1}d_{-2}d_{-3}$ from a base $b$ number system. This number has two parts separated with a decimal point-integral part ($d_{2}d_{1}d_{0}$) and fractional part ($d_{-1}d_{-2}d_{-3}$). The generalized format of converting this number to decimal number is written as:

$$Total Decimal Value=\sum_{i=b_{min}}^{b_{max}} d_{i} (radix)^{i}$$

In this expression, $b_{max}$ represents the highest position number that contains a numeral greater than
0. The variable $b_{min}$ represents the lowest position number that contains a numeral greater than 0.

Example 1. Convert $34.15_{8}$ to a decimal number.

Using the formula mentioned above, we have:

$3\cdot 8^{1}+4\cdot 8^{0}+1\cdot 8^{-1}+5\cdot 8^{-2}=3\cdot 8+4\cdot 1+1\cdot \displaystyle{\frac{1}{8}}+5\cdot \displaystyle{\frac{1}{64}}=28.203125$

#### 3.2. Converting from Decimal to any other base

We can convert a decimal number to any other base using just a few simple steps:

1. Divide the decimal number to be converted by the value of the new base.
2. Write a remainder aside
3. Divide the quotient of the previous divide by the new base.
4. Write a remainder aside
5. Repeat Steps 3 and 4 until the quotient becomes zero in Step 3.

The required number is then consisting of remainders written from bottom to top, left to right.

Example 2. Convert 25 to a binary number. Following the rule of converting decimal numbers to any other base, the required number is $11001_{2}$.

Example 3. Convert 2489 to a hexadecimal number. Remember, equivalent to number 11 in hexadecimal number system is letter B.

Following the rule of converting decimal numbers to any other base, the required number is $9B9_{16}$.

#### 3.3. Equivalence between different number systems ### 4. Shortcuts for changing between base 2 and base 8 and between base 2 and base 16

We’ve learned that we can convert a number from any base to a number of any base by converting it to decimal first. For example, if we want to covert a base 3 number to a base 7 number, first step is to convert a base 3 number to decimal and then to convert this decimal number to a base 7 number.

We can use the same procedure to convert a binary number to octal or hexadecimal number, but there are some useful shortcuts that will make the process easier. Let’s have a look at the following example:

Example 4. Convert $100100010101111_{2}$ to a hexadecimal number.

To convert a binary number to a hexadecimal number, we could simply break a binary number into groups of 4 digits (starting at the right and adding leading zeros if one runs out of digits) and then reinterpreting these groups of 4 as hexadecimal values listed in the table above. That being said, we have:

$100100010101111_{2}=0100 1000 1010 1111$

$0100=4$, $1000=8$, $1010=A$, $1111=F$

$100100010101111_{2}=48AF_{16}$

Similar to this, to convert a binary number to an octal number, we could simply break a binary number into groups of 3 digits and the rest of the procedure is the same as converting binary number to a hexadecimal number. Let’s covert the same binary number to an octal number:

$100100010101111_{2}=100 100 010 101 111$

$100=4$

$010=2$

$101=5$

$111=7$

$100100010101111_{2}=44257_{8}$

Reversing the process is even easier. Suppose we wish to convert $FC7_{16}$ to binary form. From the table we can read binary values for each digit of the hexadecimal number:

$F_{16} = 1111_{2}$ $C_{16} = 1100_{2}$ $7_{16} = 0111_{2}$

$FC7_{16}=111111000111_{2}$

Process of converting octal number to binary form is just the same.