Operações aritméticas binárias – brincando com os números

Binary arithmetic operations – playing with numbers

In the previous tutorial, we discussed how any information can be represented by numbers and a set of numbers (code systems) can be used to store and manipulate information. Much of the information in the real world is mathematical in nature, such as counting things, measuring quantities, etc. This information may also have mathematical relationships. In order for a computer (digital circuit) to be able to perform calculations (mathematical operations) on such information, it must first be capable of performing arithmetic operations. Arithmetic operations are the basic mathematical operations. Only by performing arithmetic operations can other algebraic operations be performed on numerical data.

Digital circuits only understand and manipulate binary numbers. Therefore, arithmetic operations can be performed with data only in binary form. Digital circuits implement various arithmetic operations (binary arithmetic) with the help of logic gates. The electronic circuit of a binary adder (constructed by logic gates) with suitable shift registers can perform all arithmetic operations. Before understanding how digital circuits capable of performing mathematical operations can be built using logic gates, it is important to understand how various arithmetic operations are performed in binary form. So, let's learn the basics of Boolean algebra.

Imagem Representacional de Operações Aritméticas Binárias

Fig. 1: Representational Image of Binary Arithmetic Operations

Any binary number consists of 0 and 1. A binary number is formed by placing 0 and 1 at different positional weights in the number. Arithmetic operations such as addition, subtraction, multiplication and division of binary numbers follow the rules summarized in the table below –

Tabela Listagem de Operações Aritmáticas Binárias

Fig. 2: Table listing binary arithmetic operations

Binary Addition

The addition of two binary numbers is done in the same way as for decimal numbers. The addition is carried out starting from the least significant bits and proceeds to the most significant bits, each time adding the carry resulting from the previous addition. For example, the addition of binary numbers (1010)2 and (1111)2 is done as follows –

Tabela mostrando adição binária

Fig. 3: Table showing binary addition

1) The least significant bits are added i.e. 0 + 1 = 1 with carry 0. The addition performed above involves the following steps –

2) The carry in the previous step is added to the next highest significant bits, i.e. 1 + 1 + 0 = 0 with a carry of 1.

3) The carry in the above step is added to the next highest significant bits, i.e. 0 + 1 + 1 = 0 with a carry of 1.

4) The previous carry is added to the most significant bits, i.e. 1 + 1 + 1 = 1 with a carry 1.

So the sum is (11001)2. Addition is also shown in the decimal number system to compare results. It can be seen that whether numbers are added in decimal form or binary form, the end result is always equivalent.

Binary Subtraction

Just as the subtraction of decimal numbers is done, the same way the subtraction of binary numbers is done. Subtraction is performed starting from the least significant bits and proceeds to the most significant bits. For example, consider subtracting (1101)2 by (1001)2 as follows –

Tabela mostrando subtração binária
Fig. 4: Table showing binary subtraction
The subtraction performed above involves the following steps –

1) The LSB in the first column are 1 and 1. Therefore, the difference 1 – 1 = 0.

2) In the second column, subtraction is performed as 0 – 0 = 0.

3) In the third column, the difference is given by 1 – 0 = 1.

4) In the fourth column (MSB), the difference is given by 1 – 1 = 0.

Therefore, the difference between the two binary numbers is (0100)2.

When 1 is subtracted from 0, the 1 is borrowed from the next higher significant bit. Binary subtraction with loan case is shown below –

Tabela mostrando subtração binária com empréstimo
Fig. 5: Table showing binary subtraction with borrowing
The subtraction with loan case carried out above involves the following steps –

1) The least significant bits in the first column are 1 and 1. Therefore, the difference is 1 – 1 = 0.

2) In the second column it is not possible to subtract 1 from 0. Therefore, a 1 must be borrowed from the next MSB (3 third chunk). Bit since the 3rd bit is also 0, the loan should be done in MSB ( 4th bit). Borrowing 1 from 4th bit results in 1 and 10 with weight 4 in 3rd column and 0 in 4th column as shown above. Now, subtraction is performed as 10 – 1 = 1.

3) In the third column, the difference is given by 1 – 1 = 0.

4) In the fourth column (MSB), the difference is given by 0 – 0 = 0.

Complements of 1 and 2 Subtracting one number from another can be performed by adding the complement of the subtrahend to the minuend. The exact difference can be obtained with small manipulations.

1's complement subtraction

Subtracting binary numbers using the 1's complement method allows subtraction only by addition. The 1's complement of a binary number can be obtained by changing all 1s to 0s and all 0s to 1s. Subtracting a smaller number from a larger number using the 1's complement method is done as follows –

1) Determine the 1's complement of the smaller number.

2) Add this to the larger number.

3) Remove the carry and add it to the result. This transportation is called final transportation.

For example, subtraction of (1010)2 from (1111)2 using compliment can be done as follows –

Tabela mostrando a subtração do complemento de 1

Fig. 6: Table showing 1's complement subtraction

1) Determine the 1's complement of the larger number. Subtracting a larger number from a smaller number by the 1's complement method involves the following steps –

2) Add this to the smaller number.

3) The answer is the 1's complement of the true result and has the opposite sign. There is no transport. The difference is a negative number. For example, subtraction of (1111)2 from (1010)2 using compliment can be done as follows –

Tabela mostrando a subtração do complemento de 1

Fig. 7: Table showing 1's complement subtraction

2's complement subtraction

The 2's complement of a binary number can be obtained by adding 1 to its 1's complement. Subtracting a smaller number from a larger number by the 2's complement method involves the following steps –

1) Determine the 2's complement of the smaller number.

2) Add this to the larger number.

3) Omit transportation.

Subtracting a larger number from a smaller number by the 2's complement method involves the following steps –

1) To subtract the smaller number from the larger number, first take the 1's complement of the smaller number.

2) Add 1 to the smaller number that was given 1's complement in the above step to get 2's complement.

3) Add the 2's complement number determined in the above step to the larger number given.

4) Discard the carry, the difference is the result obtained with a negative sign.

For example, subtraction of (1010)2 from (1111)2 using 2's complement is done as follows –

Tabela mostrando a subtração do complemento de 2

Fig. 8: Table showing 2's complement subtraction

Binary Multiplication

Binary multiplication is as simple as decimal multiplication. The procedure is the same as decimal multiplication. For example, the multiplication of (1011)2 and (1101)2 can be done as follows –

Imagem mostrando multiplicação binária

Fig. 9: Image showing binary multiplication

The multiplication performed above involves the following steps –

1) The least significant bit of the multiplier is taken. If the multiplier bit is 1, the multiplicand is copied as such, and if the multiplier bit is 0, a 0 is placed in all bit positions.

2) The next significant bit of the multiplier is taken and the partial product is written with a shift to the left, as in step 1.

3) Step 2 is repeated for all other bits of greater significance and each time a left shift is given.

4) When all bits of the multiplier are taken into account, the partial product terms are added, which gives the real product of the multiplier and the multiplicant.

Binary Division

Binary division is done in a similar way to decimal division. For example, dividing (1011)2 by (11)2 can be done as follows –

Q = 11

11 1011 R = 10

11

101

11

10

The division carried out above involves the following steps –

1) The MSB of the dividend is subtracted from the divisor. If there is a need to borrow, the MSB is used to borrow 1. The difference is noted and the LSB next to it is written off. The divisor as 1 or 0 is written from left to right in the quotient.

2) Step 1 is repeated until there is a remainder smaller than the divisor.

3) The quotient is written down from left to right, which is the result of the division.

This is how the arithmetic operations of addition, subtraction, multiplication and division can be done on binary numbers. In the next tutorial, learn about logical operations on binary numbers . The logic gates that form digital circuits perform logical operations. Arithmetic operations are also performed in digital circuits with the help of logical operations only with the help of logic gates and their interconnections in the data paths.

Back to the blog

Leave a comment

Comments need to be approved before publication.