Arithmetic operations in various systems. Theory on number systems. Positional number systems

Addition and subtraction

In a system with a base, the numbers 0, 1, 2, ..., s - 1 serve to designate zero and the first c-1 natural numbers. To perform the operation of addition and subtraction, a table of addition of single-digit numbers is compiled.

Table 1 - Binary addition

For example, the addition table in hexadecimal number system:

Table 2 - Addition in the hexadecimal system

The addition of any two numbers written in the base c number system is carried out in the same way as in the decimal system, by digits, starting from the first digit, using the addition table of this system. The numbers to be added are signed one after the other so that the digits of the same digits stand vertically. The result of the addition is written under the horizontal line drawn below the summand numbers. Just as when adding numbers in the decimal system, in the case when the addition of digits in any digit gives a two-digit number, the last digit of this number is written to the result, and the first digit is added to the result of adding the next digit.

For example,

You can justify the indicated rule for adding numbers using the representation of numbers in the form:

Let's look at one of the examples:

3547=3*72+5*71+4*70

2637=2*72+6*71+3*70

(3*72+5*71+4*70) + (2*72+6*71+3*70) =(3+2)*72+(5+6)*7+(3+4)=

5*72+1*72+4*7+7=6*72+4*7+7=6*72+5*7+0=6507

We sequentially select the terms according to the degree of the base 7, starting from the lowest, zero, degree.

Subtraction is also carried out by digits, starting from the lowest, and if the digit of the reduced is less than the digit of the subtracted, then one is “occupied” from the next digit of the reduced and the corresponding digit of the subtrahend is subtracted from the resulting two-digit number; when subtracting the digits of the next digit, in this case, you need to mentally reduce the digit of the one being reduced by one, but if this digit turned out to be zero (and then its reduction is impossible), then you should “take” one from the next digit and then reduce by one. There is no need to create a special subtraction table, since the addition table gives the results of the subtraction.

For example,

Multiplication and division

To perform the operations of multiplication and division in a system with base c, a multiplication table of single-digit numbers is compiled.

Table 3 - Multiplication of single digit numbers

Table 4 - Multiplication in hexadecimal number system

The multiplication of two arbitrary numbers in a system with base c is carried out in the same way as in the decimal system - by a “column”, that is, the multiplicand is multiplied by the digit of each digit of the multiplier (successively) with the subsequent addition of these intermediate results.

For example,

When multiplying multi-digit numbers in intermediate results, the base index is not set:

Division in systems with base c is done by the angle, just as in the decimal number system. In this case, the multiplication table and the addition table of the corresponding system are used. The situation is more complicated if the result of division is not a finite c-ary fraction (or an integer). Then, when performing the division operation, it is usually required to select the non-periodic part of the fraction and its period. The ability to perform the division operation in the c-ary number system is useful when translating fractional numbers from one number system to another.

For example:


Converting numbers from one number system to another

There are many different ways to translate numbers from one number system to another.

division method

Let the number N=an an-1 be given. . . a1 a0 p.

To obtain a record of the number N in a system with base h, you should represent it in the form:

N=bmhm+bm-1hm-1+... +b1h+b0 (1)

where 1

N=bmbm-1... b1boh (2)

From (1) we get:

N= (bmhm-1+...+b)*h +b0 = N1h+b0, where is 0? b0 ?h (3)

That is, the number b0 is the remainder of dividing the number N by the number h. Incomplete quotient Nl = bmhm-1+ . . . +b1 can be represented as:

Nl = (bmhm-2 + ... + b2)h + b1 = N2h+b1, where is 0? b2 ?h (4)

Thus, the digit bi in the notation (2) of the number N is the remainder of dividing the first partial quotient N1 by the base h of the new number system. The second incomplete quotient N2 can be represented as:

N2 = (bmhm-3+ ... +b3)h+b2, where is 0? b2 ?h (5)

that is, the number b2 is the remainder of dividing the second partial quotient N2 by the base h of the new system. Since the incomplete quotients decrease, this process is finite. And then we get Nm = bm, where bm

Nm-1 = bmh+bm.1 = Nmh+bm.1

So the sequence of digits is bm, bm-1 . . ,b1,b0 in the representation of the number N in the number system with base h is the sequence of residues of the consecutive division of the number N by the base h, taken in reverse order.

Consider an example: Convert the number 123 to hexadecimal:

Thus, the number 12310=7(11)16 or can be written as 7B16

Let's write the number 340227 in the quinary number system:

Thus, we get that 340227=2333315

Notation(SS) is a set of techniques and rules for writing numbers using a specific set of characters.
Alphabet SS - a set of characters (numbers) used to write a number.
Base SS (SS alphabet power) - the number of characters (digits) of the SS alphabet.
All number systems are divided into positional and non-positional. non-positional a number system is a system in which the quantitative equivalent of each digit does not depend from its position (place, position) in the notation of the number.
So, in non-positional number systems, the position that the digit occupies in the notation of the number does not play a role. For example, the Roman number system is non-positional. In the numbers XI and IX, the "weight" of both numbers is the same, regardless of their location.

Positional number systems

A positional number system is a system in which the value of a digit depends from its place (position) in the notation of the number. The base of a number system is the number of characters or symbols used to represent a number in a given number system
The base of the number system determines its name: the base p is the p-th number system.
For example, the number system mostly used in modern mathematics is the positional decimal system, its base is ten. To write any numbers, it uses ten well-known digits (0,1,2,3,4,5,6,7,8,9).

So, we said that in positional number systems, the position that the digit occupies in the notation of the number matters. So, the entry 23 means that this number can be made up of 3 units and 2 tens. If we change the positions of the digits, we get a completely different number - 32. This number contains 3 tens and 2 units. The "weight" of a two has decreased tenfold, while the "weight" of a three has increased tenfold. Expanded notation of a number
Any number N in positional number system with base p can be represented as a polynomial in p:
N=a k p k + a k-1 p k-1 +a k-2 p k-2 +...+a 1 p 1 +a 0 p 0 +a -1 p -1 +a -2 p -2 + ...,
where N is a number, p is the base of the number system (p>1), and i are the digits of the number (coefficients at the degree p).
Numbers in the p-th number system are written as a sequence of digits:
N=a k a k-1 a k-2 ...a 1 a 0 , a -1 a -2...
A comma in a sequence separates the integer part of the number from the fractional part.
3210 -1-2
N= 4567,12 10 =4 *10 3 +5 *10 2 +6 *10 1 +7 *10 0 +1 *10 -1 +2 *10 -2

Binary number system

To write numbers, only two digits are used - 0 and 1. The choice of a binary system for use in a computer is explained by the fact that the electronic elements that make up a computer can only be in two well-distinguishable states. Essentially, these elements are switches. As you know, the switch is either on or off. There is no third. One of the states is indicated by the number 1, the other - 0. Thanks to these features, the binary system has become the standard for building computers.
In this number system, any number can be represented as:
N=a k 2 k + a k-1 2 k-1 +a k-2 2 k-2 +...+a 1 2 1 +a 0 2 0 +a -1 2 -1 +a -2 2 - 2+....
For example: 11001.01 2 =1 *2 4 +1 *2 3 +0 *2 2 +0 *2 1 +1 *2 0 +0 *2 -1 +1 *2 -2

Binary arithmetic

Arithmetic operations in all positional number systems are performed according to the same well-known rules.

Addition

Consider the addition of numbers in the binary number system. It is based on the addition table of single-digit binary numbers:

0+0=0
0+1=1
1+0=1
1+1=10
1+1+1=11

It is important to pay attention to the fact that when adding two units, the bit overflows and a transfer to the highest bit occurs. An overflow occurs when the value of the number in it becomes equal to or greater than the base of the number system. For the binary number system, this value is equal to two.
The addition of multi-digit binary numbers occurs in accordance with the above addition table, taking into account possible transfers from the lower digits to the higher ones.

Subtraction

Consider the subtraction of binary numbers. It is based on a subtraction table of single-digit binary numbers. When subtracting from a smaller number (0) a larger one (1), a loan is made from the highest order. In the table, the loan is indicated by 1 with a bar.

0-0=_0
0-1=11
1-0=1
1-1=0

Addition and subtraction of one-digit binary numbers
Addition and subtraction of multidigit binary numbers (examples)

Multiplication

Multiplication is based on the multiplication table of single-digit binary numbers:

0*0=0
0*1=0
1*0=0
1*1=1

Multiplication of multi-digit binary numbers occurs in accordance with the above multiplication table according to the usual scheme used in the decimal number system, with successive multiplication of the multiplier by the next digit of the multiplier.

Division

The division operation is performed according to an algorithm similar to the division operation algorithm in the decimal number system.

Because in the binary system, only 2 digits are used to write numbers - 0 and 1, which means that when adding 1 + 1, 0 is written in the least significant bit, and 1 goes to the most significant bit.

By analogy with 10-ss: 9 + 1 (the number ten is not in the notation of numbers), 0 and 1 are written in the most significant digit, it turns out 10.

Examples

1) Add 10110 2 and 111011 2 in a column. Units above indicate a carry from the previous digit:

2) Perform addition for the following binary numbers:

3) Add numbers: 10000000100 2 + 111000010 2 and check

10000000100 2 + 111000010 2 = 10111000110 2 .

Let's check the calculation results by transferring them to the decimal number system. To do this, we translate each term and the sum into the decimal number system, perform the addition of the terms in the decimal number system. The result must match the sum.

10000000100 2 = 1 × 2 10 + 1 × 2 2 = 1024 + 4 = 1028 10

111000010 2 = 1× 2 8 + 1× 2 7 + 1× 2 6 + 1 × 2 1 = 256 + 128 + 64 + 2 = 450 10

10111000110 2 = 1 × 2 10 + 1 × 2 8 + 1 × 2 7 + 1 × 2 6 + 1 × 2 2 + 1 × 2 1 =

1024 + 256 + 128 + 64 + 4 + 2 =1478 10

1028 10 + 450 10 =1478 10 .

The results match, therefore, the calculations in the binary system are correct.

Octal numbers

Octal Addition Table

+

When calculating in the octal system, you need to remember that the maximum digit is 7. A carry during addition occurs when the sum in the next digit is greater than 7. The loan from the highest digit is 10 8 = 8, and all “intermediate” digits are filled with the number 7 - the highest digit of the number system.

Example

1) In the example, the entry 1⋅8 + 2 means that the result is a sum greater than 7, which does not fit into one digit. The unit goes into the transfer, and the deuce remains in this category.

2) Perform addition 223,2 8 + 427,54 8 and check the result.

223,2 8 + 427,54 8 = 652,74 8 .

Let's check the calculation results by converting to the decimal number system:

223.2 8 = 2 × 8 2 + 2 × 8 1 + 3 × 8 0 + 2 × 8 -1 = 128 + 16 + 3 + 0.25 =

427.54 8 = 4 × 8 2 + 2 × 8 1 + 7 × 8 0 + 5 × 8 -1 + 4 × 8 -2 =

256 + 16 + 7 + 0,625 + 0,0625= 279,6875 10

652.74 8 = 6 × 8 2 + 5 × 8 1 + 2 × 8 0 + 7 × 8 -1 + 4 × 8 -2 =

384 + 40 + 2 + 0,875 + 0,0625 = 426,9375 10

147,25 10 + 279,6875 10 =426,9375 10

The results match, therefore, the calculations in the octal number system are correct.

Hexadecimal numbers

Hexadecimal addition table

+ A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A A B C D E F
B B C D E F 1A
C C D E F 1A 1B
D D E F 1A 1B 1C
E E F 1A 1B 1C 1D
F F 1A 1B 1C 1D 1E

When performing addition, you need to remember that in a system with base 16, a carry appears when the sum in the next digit exceeds 15. It is convenient to first rewrite the original numbers, replacing all letters with their numerical values.

Examples

2) Perform addition 3B3,6 16 + 38B,4 16 and check

3B3.6 16 + 38B.4 16 = 73E,A 16 .

Let's check:

3B3.6 16 = 3 × 16 2 + 11 × 16 1 + 3 × 16 0 + 6 × 16 -1 = 768 + 176 +

3 + 0,375 = 947,375 10

38B,4 16 = 3 × 16 2 + 8 × 16 1 + 11 × 16 0 + 4 × 16 -1 = 768 + 128 +

11 + 0,25 = 907,25 10

73E,A 16 = 7 × 8 2 + 3 × 8 1 + 14 × 8 0 + 10 × 8 -1 = = 1792 + 48 + 14 + 0.625 = 1854.625 10

947,375 10 + 907,25 10 = 1854,625 10 .

The results match, so the hexadecimal calculations are correct.

Subtraction

binary numbers

Subtraction is performed in much the same way as in the decimal system. Here are the basic rules:

0 – 0 = 0, 1 – 0 = 1, 1 – 1 = 0, 10 2 – 1 = 1.

In the latter case, you have to take a loan from the previous category.

Subtraction is performed by analogy with the decimal number system.

To understand the principle, let's temporarily return to the decimal system. Let's subtract the number 9 in a column from the number 21:

Since 9 cannot be subtracted from 1, you need to borrow from the previous digit, which contains 2. As a result, 10 is added to the lower digit, and 2 is reduced to 1 in the next digit. Now you can subtract: 1 + 10 - 9 = 2. In the higher digit subtract zero from the remaining one:

A more complicated case is a loan from a distant (not the nearest) category. Subtract 9 from 2001. In this case, it is not possible to borrow from the nearest digit (there is 0), so we take a loan from the digit where the number 2 is located. As a result, all intermediate digits are filled with the number 9, this is the highest digit of the decimal number system:

In the binary number system, when a loan is taken, not 10 is added to the “working” category, but 102 = 2 (the base of the number system), and all “intermediate” digits (between the “working” and where the loan comes from) are filled not with nines , but by units (highest digit of the number system).

Examples

If you want to subtract a larger number from a smaller one, subtract the smaller one from the larger one and put a minus sign at the result:

3) 4)

Octal numbers

1)

When subtracting "-1" means that there used to be a loan from this category (its value decreased by 1), and "+ 8" means a loan from the next category.

2) Subtraction

Hexadecimal numbers

When subtracting the loan from the most significant digit, it is equal to 10 16 = 16, and all "intermediate" digits are filled with the number F - the most significant digit of the number system.

For example,

1)

2)

Multiplication

binary numbers

X

Multiplication and division by a column in the binary system are performed in much the same way as in the decimal system (but using the rules of binary addition and subtraction).

for example ,

1) 2)

Octal numbers

Octal multiplication table

´

Using the octal multiplication table, using the same rules that apply in the decimal number system, multiplication and division of octal multi-digit numbers are performed.

Example

Hexadecimal numbers

Multiplication table

´ A B C D E F
A B C D E F
A C E 1A 1C 1E
C F 1B 1E 2A 2D
C 1C 2C 3C
A F 1E 2D 3C 4B
C 1E 2A 3C 4E 5A
E 1C 2A 3F 4D 5B
1B 2D 3F 5A 6C 7E
A A 1E 3C 5A 6E 8C
B B 2C 4D 6E 8F 9A A5
C C 3C 6C 9C A8 B4
D D 1A 4E 5B 8F 9C A9 B6 C3
E E 1C 2A 7E 8C 9A A8 B6 C4 D2
F F 1E 2D 3C 4B 5A A5 B4 C3 D2 E1

Example

Division separately to the decimal system, since for numbers from 0 to 7 their octal notation is the same as decimal);

3) Add up

Solution (via hex):

1) (first transferred to the binary system, then the binary notation of the number was divided into tetrads from right to left, each tetrad was converted to hexadecimal system; while tetrads can be converted from the binary system to decimal, and then replace all numbers greater than 9 with letters - A, B, C, D, E, F);

2) , there is no need to translate anywhere;

3) fold

4) translate all answers into hexadecimal system:

121 8 \u003d 001 010 001 2 \u003d 0101 0001 2 \u003d 51 16 (transferred to the binary system in triads, divided into tetrads from right to left, each tetrad was translated separately to the decimal system, all numbers greater than 9 were replaced with letters - A, B, C, D, E, F).

171 2 = 001 111 001 2 = 0111 1001 2 = 79 16 ,

69 16, no need to translate

1000001 2 = 0100 0001 2 = 41 16 .

In addition to decimal, there are an unmeasurable number of other systems, some of which are used to represent and process information in a computer. There are two types of number systems: positional and non-positional.

Non-positional systems are those in which each digit retains its value regardless of its location in the number. An example is the Roman numeral system, which uses numbers such as I, V, X, L, C, D, M, etc.

positional number systems are called in which the value of each digit depends on its location. The positional system is characterized by the basis of calculus, which will be understood as such a number £, which shows how many units of any category are needed to obtain a unit of higher order.

For example, you can write

What corresponds to the numbers in the decimal number system

The index below indicates the basis of the number.

To translate positive numbers from one number system to another, two rules are known:

Translation of numbers from the system , into the system ;

Translation of numbers from the system , into the system using system arithmetic ;

Consider the first rule . Let's say the number is in decimal must be represented in binary . To do this, this number is divided by the base of the system presented in the system , i.e. by 2 10 . The remainder of the division will be the least significant digit of the binary number. The integer part of the result of the division is again divided by 2. Repeat the division operation as many times until the quotient is less than two.

Example: Convert 89 10 to binary using decimal arithmetic

89 10 → 1011001 2

The reverse translation, according to the same rule, is as follows:

1011001 2 convert to decimal using binary arithmetic

The binary numbers 1000 and 1001 according to Table 2.1 are respectively 8 and 9. Therefore, 1011001 2 → 89 10

Sometimes it is more convenient to carry out a reverse translation using the general rule for representing a number in any number system.

Consider the second rule. Translation of numbers from the system , into the system using system arithmetic . To carry out the transfer, you need each digit of the number in the system multiply by the base of the number system represented in the number system and in the degree of the position of this number. After that, the resulting products are summarized.

Arithmetic and logical operations

Arithmetic operations

Consider the arithmetic of the binary number system, since it is it that is used in modern computers for the following reasons:

There are the simplest physical elements which have only two states and which can be interpreted as 0 and 1;

Arithmetic processing is very simple.

Numbers in octal and hexadecimal systems are commonly used as a substitute for the long and therefore inconvenient representation of binary numbers.

The operations of addition, subtraction and multiplication in the binary system are:

As has already been demonstrated earlier, in order to get by with only the adder, that is, to perform only addition operations, the subtraction operation is replaced by addition. For this, a negative number code is formed as an addition to the numbers 2, 10, 100, etc.

Arithmetic operations in positional number systems

Arithmetic operations in all positional number systems are performed according to the same well-known rules.

Addition. Consider the addition of numbers in the binary number system. It is based on the addition table of single-digit binary numbers:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10

It is important to pay attention to the fact that when adding two units, the bit overflows and a transfer to the highest bit occurs. An overflow occurs when the value of the number in it becomes equal to or greater than the base.

The addition of multi-digit binary numbers occurs in accordance with the above addition table, taking into account possible transfers from the lower digits to the higher ones. As an example, let's add the binary numbers 110 2 and 11 2 in a column:

Let's check the correctness of calculations by addition in the decimal number system. Let's convert the binary numbers to the decimal number system and then add them:

110 2 = 1 × 2 2 + 1 × 2 1 + 0 × 2 0 = 6 10 ;

11 2 = 1 × 2 1 + 1 × 2 0 = 3 10 ;

6 10 + 3 10 = 9 10 .

Now we translate the result of binary addition into a decimal number:

1001 2 = 1 × 2 3 + 0 × 2 2 + 0 × 2 1 + 1 × 2 0 = 9 10 .

Compare the results - the addition is correct.

Subtraction. Consider the subtraction of binary numbers. It is based on a subtraction table of single-digit binary numbers. When subtracting from a smaller number (0) a larger one (1), a loan is made from the highest order. In the table, the loan is indicated by 1 with a line:

Multiplication. Multiplication is based on the multiplication table of single-digit binary numbers:

Division. The division operation is performed according to an algorithm similar to the division operation algorithm in the decimal number system. As an example, let's divide the binary number 110 2 by 11 2:

To perform arithmetic operations on numbers expressed in different number systems, you must first translate them into the same system.

Tasks

1.22. Carry out addition, subtraction, multiplication and division of binary numbers 1010 2 and 10 2 and check the correctness of arithmetic operations using an electronic calculator.

1.23. Add octal numbers: 5 8 and 4 8 , 17 8 and 41 8 .

1.24. Subtract hexadecimal numbers: F 16 and A 16, 41 16 and 17 16.

1.25. Add numbers: 178 and 1716, 418 and 4116