Multiplication of numbers, Algorithms for multiplying...

Multiplication of numbers

Algorithms for multiplying binary numbers

Let's consider algorithmic features of realization of operation of multiplication of positive и-bit binary numbers А = а { а п _ 2 ... a k ... a i a 0 and B = b n_ { > B n _ 2 ... b k ... b x b Q, where A is a multiplicand, B is a multiplier. Individual bits a k and b are multiplied by binary numbers according to the rules given in Table. 2.10.

Table 2.10

k

a k

& gt; h

Arithmetic multiplication Pk = "k * b k

Logical multiplication Pk ~ a b L to

Addition modulo 2 Pk = & lt; 4® b to

0

0

0

0

0

0

1

0

1

0

0

1

2

1

0

0

0

1

3

1

1

1

1

0

It should be noted that the operation of arithmetic multiplication of single-digit binary numbers is identical to the operation of logical multiplication. Therefore, with its hardware implementation, you can use logical elements.

Representing the multiplier in the form of an expanded binary number

you can get the following expression for the product of binary numbers:

(2.18)

where - k-e is a partial product.

Two well-known multiplication rules follow from the expression (2.18): starting from the lowest and the highest digits b to the factor B.

Example 2.23. Let's illustrate the multiplication rules for 3-bit binary numbers A = 111 and B = 101, beginning with the lowest and highest digits of the multiplier (Figure 2.12).

Multiplication rules

Fig. 2.12. Multiplication rules

Multiplying the binary number b by ■ A by 2 k is equivalent to shifting it to the left by k digits. As follows from (2.18), when multiplying of the lower bit of the factor b 0, the exponents k of the coefficient 2 k increase sequentially taking the values ​​ to = 0, 1, 2, ..., n - 1. This means that each subsequent partial product is shifted one digit to the left. When multiplying ω of the highest bit of the factor b n, the opposite picture is observed: the coefficients k 2 k decrease, the values ​​of to = n - 1, n-2, ..., 2, 1, 0. Therefore, each subsequent partial product is shifted one bit to the right.

Using Horner's method, we transform expression (2.18) to the form (2.19):

(2.19)

According to (2.19), multiplication begins with the highest bit b n [ = b T Then, by multiplying by 21, a left shift of the (n-1) and then each subsequent sum of partial products (with the exception of the latter) is also shifted to the left by one digit.

Example 2.24. Multiplication of 3-bit binary numbers A = 111 and B = 101 (Figure 2.13) using the algorithm described by formula (2.19), which has the following form for n = 3:

where b 2 = 1, b x = 0, b 0 = 1 (Figure 2.13).

Multiplication by the algorithm (2.19) with the left shift of the intermediate results

Fig. 2.13. Multiplication by the algorithm (2.19) with the left shift of the intermediate results

Another form of representation of the product (2.18) according to the Horner scheme

(2.20)

It follows from (2.20) that multiplication begins with the lower order b 0 of the factor B. Then, by multiplying by 2 1, the partial product b 0 ■ A to the right for one charge, and then each subsequent sum of partial products (with the exception of the last one) is also shifted to the right by one digit.

Example 2.25. Multiplication of 3-bit binary numbers A = 111 and B = 101 but the algorithm described by formula (2.20), which has for n = 3 the following view:

where (Figure 2.14).

Multiplication by the algorithm (2.20) with the right shift of the intermediate results

Fig. 2.14. Multiplication according to the algorithm (2.20) with the right shift of the intermediate results

For the multiplication of positive integers, the number of digits of the product does not exceed 2π. In the case when the multiplier A and the factor B may have different signs, it becomes necessary to determine the sign of the product. For this, a logical addition operation modulo two or unequivities is performed on signed digits of the factors (see Table 2.10):

(2.21)

where p 2n , and n , b n - the sign values ​​of the product P and Lie factors B; ® - designate the logical operation of non-equality.

If the multiplier A and the multiplier B have different signs, then the result of the unequality operation is equal to one, and if - the same signs, then the result is zero. Therefore, if A and B have:

• different signs, then p 2n = a n ® b n = 1 Φ 0 = 0 © 1 = 1, which corresponds to the negative sign of the product P;

• the same signs, then p 2n = a n ® b n = 1 ® 1 = 0 © 0 = 0, which corresponds to the positive sign of the product P.

Given a known product sign, its absolute value is determined by multiplying the moduli of the factors (without taking into account their signs).

Ошибка в функции вывода объектов.