# 2: Numbering systems

## 2.1 Decimal, hexadecimal and binary numbering systems

There are different systems that can be use to write a certain number.

As an example, if we need to write the number ‘sixty-three’, we can use different numbering systems, as will be illustrated in this section.

### 2.1.1 Decimal Numbering system

We learned this ordinary system from the childhood.

This system is formed from 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) so; it is called the ‘decimal numbering system’.

As an example, to write ‘sixty-three’ in the decimal numbering system, we simply write ‘63’.

### 2.1.2 Hexadecimal numbering system

This is a numbering system that is formed from 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F).

As an example, if we need to write ‘sixty-three’ in the hexadecimal numbering system, we will write ‘3F’.

The digits from ‘A’ to ‘F’ in the hexadecimal system are equivalent to the numbers from ‘10’ to ‘15’ in the decimal system respectively.

Figure 2.1: the relation between the hexadecimal and the decimal numbering systems.

### 2.1.3 Binary numbering system

This numbering system is formed from only two digits (0 and 1).

As an example, if we need to write ‘sixty-three’ in the binary numbering system, we will write ‘00111111’.

Binary numbering system, basic information

If we wrote a binary number ‘10010010’, we should know the following,

Figure 2.2: the binary number basic elements

1. 1. Every ‘0’ or ‘1’ of the above digits is called a ‘bit’.
2. 2. Every 4 bits are called a ‘nibble’.
3. 3. Every two nibbles (8 bits) are called a ‘byte’.

This means that, 8 bits = 2 nibbles = 1 byte.

1. 4. The most left bit is called the ‘most Significant Bit’ or the ‘MSB’.
2. 5. The most right bit is called the ‘least Significant Bit’ or the ‘LSB’.

## 2.2 How to convert from binary to decimal

To convert a number from the binary numbering system to the decimal numbering system, we should know the weight of every binary digit (bit) in this binary number.

The weight of every bit depends on its location in the binary number.

The MSB has the highest weight, while the LSB has the least weight.

As an example, if we have a binary number that is formed from eight bits. The weight of every bit will be as following,

Figure 2.3: the binary digits weight

The LSB weight = 1

The MSB weight = 128

To convert from the binary numbering system to the decimal numbering system, we multiply every bit by its weight then we aggregate all the results.

Example:

Convert the following binary number ‘10010010’ to the decimal numbering system.

We multiply every bit by its weight, and then we aggregate all the results.

So, the binary number ‘10010010’ = the decimal number ‘146’.

## 2.3 How to convert from decimal to binary

To convert from the decimal system to the binary system, we will also use the binary digits weight.

Figure 2.4: the binary digits weight

The way of conversion is as following,

We take the decimal number and divide it over the first weight 128.

We write the result as the MSB in the binary number, and take the remaining and divide it over the second weight 64.

We write the result as the bit before MSB, and take the remaining and divide it over the third weight 32.

….

We continue doing the previous steps until the last weight 1.

#### Example 1:

Convert the decimal number ‘65’ to its equivalent binary number.

65/128 = 0 and remaining 65

65/64 = 1 and remaining 1

1/32 = 0 and remaining 1

1/16 = 0 and remaining 1

1/8 = 0 and remaining 1

1/4 = 0 and remaining 1

1/2 = 0 and remaining 1

1/1 = 1 and remaining 0

So, the equivalent binary number will be = 01000001

#### Example 2:

Convert the decimal number ‘133’ to its equivalent binary number.

133/128 = 1 and remaining 5

5/64 = 0 and remaining 5

5/32 = 0 and remaining 5

5/16 = 0 and remaining 5

5/8 = 0 and remaining 5

5/4 = 1 and remaining 1

1/2 = 0 and remaining 1

1/1 = 1 and remaining 0

So, the equivalent binary number will be = 10000101

## 2.4 How to convert between hexadecimal and binary

### 2.4.1 Convert from hexadecimal to binary

The digits from ‘A’ to ‘F’ in the hexadecimal system are equivalent to numbers from ‘10’ to ‘15’ in the decimal system respectively.

Figure 2.5: the relation between the hexadecimal and the decimal numbering systems.

To convert from the hexadecimal system to the binary system, we do the following,

1. 1. Convert every digit in the hexadecimal number to its equivalent in the decimal numbering system.
2. 2. Convert every number in the decimal system to its equivalent in the binary numbering system.

Figure (2.6) illustrates how we can convert from the hexadecimal numbering system to the binary numbering system.

Figure 2.7: hexadecimal to binary conversion

### 2.4.2 Convert from binary to hexadecimal

To convert from the binary system to the hexadecimal system, we make the following.

1. 1. Convert every nibble (4 bits) in the binary number to its equivalent in the decimal system
2. 2. Convert every decimal number to its equivalent in the hexadecimal.

Figure 2.7: hexadecimal to binary conversion

## 2.5 How to convert between hexadecimal and decimal

### 2.5.1 Convert from hexadecimal to decimal

The digits from ‘A’ to ‘F’ in the hexadecimal system are equivalent to numbers from ‘10’ to ‘15’ in the decimal system respectively.

Figure 2.7: binary to hexadecimal conversion

To convert from the hexadecimal system to the decimal system, we do the following,

1. 1. Convert every digit in the hexadecimal number to its equivalent in the decimal numbering system.
2. 2. Convert every number in the decimal number to its equivalent in the binary numbering system.
3. 3. Convert the binary number to its equivalent in the decimal numbering system.

Figure (2.9) illustrates how we can convert from the hexadecimal numbering system to the decimal numbering system.

Figure 2.9: convert from the hexadecimal to the decimal numbering systems.

### 2.5.2 Convert from decimal to hexadecimal

To convert from the decimal system to the hexadecimal system, we make the opposite steps of the previous operation.

1. 1. Convert the decimal number to its binary equivalent
2. 2. Convert every nibble (4 bits) in the binary number to its equivalent in the decimal system.
3. 3. Convert every number in the decimal number to its equivalent in the hexadecimal system.

Figure 2.10: decimal to hexadecimal conversion