Subtraction operation in the binary number system. Binary arithmetic

Arithmetic operations in positional number systems

Let's take a closer look at arithmetic operations in the binary number system. Binary number system arithmetic is based on the use of tables for adding, subtracting and multiplying digits. Arithmetic operands are located in the top row and first column of the tables, and the results are at the intersection of columns and rows:

Let's look at each operation in detail.

Addition. The binary addition table is extremely simple. Only in one case when addition is performed 1+1, there is a transfer to the most significant digit. ,

Subtraction. When performing a subtraction operation, the smaller number is always subtracted from the larger number in absolute value and the corresponding sign is placed. In the subtraction table, a 1 with a bar means a loan in the highest rank.

Multiplication. The multiplication operation is performed using a multiplication table according to the usual scheme used in the decimal number system with sequential multiplication of the multiplicand by the next digit of the multiplier.

Division. The division operation is performed using an algorithm similar to the algorithm for performing the division operation in the decimal number system.

Purpose of the service. The online calculator is designed for adding binary numbers in forward, reverse and complement codes.

The following are also used with this calculator:
Converting numbers to binary, hexadecimal, decimal, octal number systems
Multiplying binary numbers
Floating point format
Example No. 1. Represent the number 133.54 in floating point form.
Solution. Let's represent the number 133.54 in normalized exponential form:
1.3354*10 2 = 1.3354*exp 10 2
The number 1.3354*exp 10 2 consists of two parts: the mantissa M=1.3354 and the exponent exp 10 =2
If the mantissa is in the range 1 ≤ M Representing a number in denormalized exponential form.
If the mantissa is in the range 0.1 ≤ M Let's represent the number in denormalized exponential form: 0.13354*exp 10 3

Example No. 2. Represent the binary number 101.10 2 in normalized form, written in the 32-bit IEEE754 standard.
Truth table


Calculation of limits

Arithmetic in binary number system

Arithmetic operations in the binary system are performed in the same way as in the decimal system. But, if in the decimal number system the transfer and borrowing are carried out by ten units, then in the binary number system - by two units. The table shows the rules for addition and subtraction in the binary number system.
  1. When adding two units in a binary number system, this bit will be 0 and the unit will be transferred to the most significant bit.
  2. When subtracting one from zero, one is borrowed from the highest digit, where there is 1. A unit occupied in this digit gives two units in the digit where the action is calculated, as well as one in all intermediate digits.

Adding numbers taking into account their signs on a machine is a sequence of the following actions:

  • converting the original numbers into the specified code;
  • bitwise addition of codes;
  • analysis of the obtained result.
When performing an operation in reverse (modified reverse) code, if as a result of addition a carry unit appears in the sign bit, it is added to the low order bit of the sum.
When performing an operation in two's complement (modified two's complement) code, if a carry unit appears in the sign bit as a result of addition, it is discarded.
The subtraction operation in a computer is performed through addition according to the rule: X-Y=X+(-Y). Further actions are performed in the same way as for the addition operation.

Example No. 1.
Given: x=0.110001; y= -0.001001, add in reverse modified code.

Given: x=0.101001; y= -0.001101, add in additional modified code.

Example No. 2. Solve examples on subtracting binary numbers using the 1's complement and cyclic carry method.
a) 11 - 10.
Solution.
Let's imagine the numbers 11 2 and -10 2 in reverse code.

The binary number 0000011 has a reciprocal code of 0.0000011

Let's add the numbers 00000011 and 11111101

7 6 5 4 3 2 1 0
1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0

7 6 5 4 3 2 1 0
1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0

An overflow occurred in the 2nd digit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 3rd digit.
7 6 5 4 3 2 1 0
1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0

7 6 5 4 3 2 1 0
1 1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0 0

7 6 5 4 3 2 1 0
1 1 1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0

7 6 5 4 3 2 1 0
1 1 1 1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0 0

7 6 5 4 3 2 1 0
1 1 1 1 1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0 0 0

7 6 5 4 3 2 1 0
1 1 1 1 1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0 0 0 0

As a result we get:
7 6 5 4 3 2 1 0
1 1 1 1 1 1 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0 0 0 0

A carryover from the sign bit has occurred. Let's add it (i.e. 1) to the resulting number (thus carrying out the cyclic transfer procedure).
As a result we get:
7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1

The result of the addition: 00000001. Let's convert it to decimal representation. To translate an integer part, you need to multiply the digit of a number by the corresponding degree of digit.
00000001 = 2 7 *0 + 2 6 *0 + 2 5 *0 + 2 4 *0 + 2 3 *0 + 2 2 *0 + 2 1 *0 + 2 0 *1 = 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 = 1
Addition result (decimal notation): 1

b) 111-010 Let's imagine the numbers 111 2 and -010 2 in reverse code.
The reverse code for a positive number is the same as the forward code. For a negative number, all digits of the number are replaced by their opposites (1 by 0, 0 by 1), and a unit is entered in the sign digit.
The binary number 0000111 has a reciprocal code of 0.0000111
The binary number 0000010 has a reciprocal code of 1.1111101
Let's add the numbers 00000111 and 11111101
An overflow occurred in the 0th digit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 1st digit.

7 6 5 4 3 2 1 0
1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0

An overflow occurred in the 1st digit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 2nd digit.
7 6 5 4 3 2 1 0
1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 0

An overflow occurred in the 2nd digit (1 + 1 + 1 = 11). Therefore, we write 1, and move 1 to the 3rd digit.
7 6 5 4 3 2 1 0
1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
1 0 0

An overflow occurred in the 3rd digit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 4th digit.
7 6 5 4 3 2 1 0
1 1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 1 0 0

An overflow occurred in the 4th bit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 5th digit.
7 6 5 4 3 2 1 0
1 1 1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 0 1 0 0

An overflow occurred in the 5th digit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 6th digit.
7 6 5 4 3 2 1 0
1 1 1 1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 0 0 1 0 0

An overflow occurred in the 6th bit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 7th digit.
7 6 5 4 3 2 1 0
1 1 1 1 1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 0 0 0 1 0 0

An overflow occurred in the 7th bit (1 + 1 = 10). Therefore, we write 0, and move 1 to the 8th digit.
7 6 5 4 3 2 1 0
1 1 1 1 1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0 1 0 0

As a result we get:
7 6 5 4 3 2 1 0
1 1 1 1 1 1 1
0 0 0 0 0 1 1 1
1 1 1 1 1 1 0 1
0 0 0 0 0 1 0 0

A carryover from the sign bit has occurred. Let's add it (i.e. 1) to the resulting number (thus carrying out the cyclic transfer procedure).
As a result we get:
7 6 5 4 3 2 1 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 1

Addition result: 00000101
We got the number 00000101. To convert the whole part, you need to multiply the digit of the number by the corresponding degree of digit.
00000101 = 2 7 *0 + 2 6 *0 + 2 5 *0 + 2 4 *0 + 2 3 *0 + 2 2 *1 + 2 1 *0 + 2 0 *1 = 0 + 0 + 0 + 0 + 0 + 4 + 0 + 1 = 5
Addition result (decimal notation): 5

Addition of binary floating point real numbers

On a computer, any number can be represented in floating point format. The floating point format is shown in the figure:


For example, the number 10101 in floating point format can be written like this:


Computers use a normalized form of writing a number in which the position of the decimal point is always given before the significant digit of the mantissa, i.e. the condition is met:
b -1 ≤|M| Normalized number - This is a number that has a significant digit after the decimal point (i.e. 1 in the binary number system). Normalization example:
0,00101*2 100 =0,101*2 10
111,1001*2 10 =0,111001*2 101
0,01101*2 -11 =0,1101*2 -100
11,1011*2 -101 =0,11011*2 -11

When adding floating-point numbers, order alignment is performed towards a higher order:

Algorithm for adding floating point numbers:

  1. Alignment of orders;
  2. Addition of mantissas in modified additional code;
  3. Normalization of the result.

Example No. 4.
A=0.1011*2 10 , B=0.0001*2 11
1. Alignment of orders;
A=0.01011*2 11 , B=0.0001*2 11
2. Addition of mantissas in the additional modified code;
MA additional mod. =00.01011
MB additional mod. =00.0001
00,01011
+ 00,00010
=
00,01101
A+B=0.01101*2 11
3. Normalization of the result.
A+B=0.1101*2 10

Example No. 3. Write a decimal number in the binary number system and add two numbers in the binary number system.

Tasks to determine values ​​in various number systems and their bases

Exercise 1. To encode the characters @, $, &, %, two-digit sequential binary numbers are used. The first character corresponds to the number 00. Using these characters, the following sequence was encoded: $%&&@$. Decode this sequence and convert the result to hexadecimal number system.

Solution.

1. Let's compare binary numbers to the characters they encode:
00 — @, 01 — $, 10 — &, 11 — %

3. Convert the binary number to the hexadecimal number system:
0111 1010 0001 = 7A1

Answer. 7A1 16.

Task 2. The garden has 100 x fruit trees, of which 33 x are apple trees, 22 x ...
– pears, 16 x – plums, 17 x – cherries. What is the base of the number system (x).

Solution.

1. Note that all terms are two-digit numbers. In any number system they can be represented as follows:
a * x 1 + b * x 0 = ax + b, where a and b are the digits of the corresponding digits of the number.
For a three-digit number it would be like this:
a * x 2 + b * x 1 + c * x 0 = ax 2 + bx + c

2. The condition of the problem is:
33 x + 22 x + 16 x + 17 x = 100 x
Let's substitute the numbers into the formulas:
3x + 3 + 2x +2 + 1x + 6 + 1x + 7 = 1x 2 + 0x + 0
7x + 18 = x 2

3. Solve the quadratic equation:
-x2 + 7x + 18 = 0
D = 7 2 – 4 * (-1) * 18 = 49 + 72 = 121. The square root of D is 11.
Roots of a quadratic equation:
x = (-7 + 11) / (2 * (-1)) = -2 or x = (-7 - 11) / (2 * (-1)) = 9

4. A negative number cannot be the base of a number system. Therefore x can only be equal to 9.

Answer. The required base of the number system is 9.

Task 3. In a number system with some base, the decimal number 12 is written as 110. Find this base.

Solution.

First, we will write the number 110 through the formula for writing numbers in positional number systems to find the value in the decimal number system, and then we will find the base by brute force.

110 = 1 * x 2 + 1 * x 1 + 0 * x 0 = x 2 + x

We need to get 12. Let's try 2: 2 2 + 2 = 6. Try 3: 3 2 + 3 = 12.

This means that the base of the number system is 3.

Answer. The required base of the number system is 3.

Hexadecimal and octal number systems

Exercise 1. What number in hexadecimal number system corresponds to the number 11000101?

Solution.

When converting a binary number to hexadecimal, the first is divided into groups of four digits, starting from the end. If the number of digits is not divisible by four, then the first four is preceded by zeros. Each four has a unique correspondence to one digit in the hexadecimal number system.

11000101 = 1100 0101 = C5 16

There is no need to have a correspondence table in front of your eyes. Binary counting of the first 15 numbers can be done in your head or written down sequentially. It should not be forgotten that 10 in the decimal system corresponds to A in hexadecimal, 11 - B, 12 - C, 13 - D, 14 - E, 15 - F.

Answer. 11000101 = C5 16

Task 2. Calculate the sum of the binary numbers x and y, with x = 10100 and y = 10101. Express the results as an octal number.

Solution.

Let's add two numbers. The rules of binary and decimal arithmetic are the same:

When converting a binary number to octal, the first is divided into groups of three digits, starting from the end. If the number of digits is not divisible by three, then the first three is preceded by zeros:

Answer. The sum of the binary numbers 10100 and 10101, represented in the octal number system, is 51.

Conversion to binary number system

Exercise 1. What is the number 37 in binary?

Solution.

You can convert by dividing by 2 and combining the remainders in reverse order.

Another way is to decompose the number into the sum of powers of two, starting with the highest, the calculated result of which is less than the given number. When converting, missing powers of a number should be replaced with zeros:

37 10 = 32 + 4 + 1 = 2 5 + 2 2 + 2 0 = 1 * 2 5 + 0 * 2 4 + 0 * 2 3 + 1 * 2 2 + 0 * 2 1 + 1 * 2 0 = 100101

Answer. 37 10 = 100101 2 .

Task 2. How many significant zeros are there in binary notation of the decimal number 73?

Solution.

Let us decompose the number 73 into the sum of powers of two, starting with the highest and subsequently multiplying the missing powers by zeros, and the existing powers by one:

73 10 = 64 + 8 + 1 = 2 6 + 2 3 + 2 0 = 1 * 2 6 + 0 * 2 5 + 0 * 2 4 + 1 * 2 3 + 0 * 2 2 + 0 * 2 1 + 1 * 2 0 = 1001001

Answer. The binary representation of the decimal number 73 has four significant zeros.

Task 3. Calculate the sum of the numbers x and y for x = D2 16, y = 37 8. Present the result in the binary number system.

Solution.

Recall that each digit of a hexadecimal number is formed by four binary digits, each digit of an octal number by three:

D2 16 = 1101 0010
37 8 = 011 111

Let's add up the resulting numbers:

Answer. The sum of the numbers D2 16 and y = 37 8, represented in the binary number system, is 11110001.

Task 4. Given: a= D7 16, b= 331 8 . Which number c, written in the binary number system, meets the condition a< c < b ?

  1. 11011001
  2. 11011100
  3. 11010111
  4. 11011000

Solution.

Let's convert the numbers to the binary number system:

D7 16 = 11010111
331 8 = 11011001

The first four digits of all numbers are the same (1101). Therefore, the comparison is simplified to comparing the lower four digits.

The first number from the list is equal to the number b, therefore, is not suitable.

The second number is greater than b. The third number is a.

Only the fourth number is suitable: 0111< 1000 < 1001.

Answer. The fourth option (11011000) meets the condition a< c < b .

Conversion to decimal number system

Exercise 1. What number does 24 16 correspond to in the decimal system?

Solution.

24 16 = 2 * 16 1 + 4 * 16 0 = 32 + 4 = 36

Answer. 24 16 = 36 10

Task 2. It is known that X = 12 4 + 4 5 + 101 2. What is the value of X in the decimal number system?

Solution.


12 4 = 1 * 4 1 + 2 * 4 0 = 4 + 2 = 6
4 5 = 4 * 5 0 = 4
101 2 = 1 * 2 2 + 0 * 2 1 + 1 * 2 0 = 4 + 0 + 1 = 5
Find the number: X = 6 + 4 + 5 = 15

Answer. X = 15 10

Task 3. Calculate the value of the sum 10 2 + 45 8 + 10 16 in decimal notation.

Solution.

Let's convert each term to the decimal number system:
10 2 = 1 * 2 1 + 0 * 2 0 = 2
45 8 = 4 * 8 1 + 5 * 8 0 = 37
10 16 = 1 * 16 1 + 0 * 16 0 = 16
The sum is: 2 + 37 + 16 = 55

Answer. 55 10

Arithmetic operations in the binary number system

Number systems

Topic number:

In the binary number system, arithmetic operations are performed according to the same rules as in the decimal number system, because they are both positional (along with octal, hexadecimal, etc.).

Addition

Addition of single-digit binary numbers is performed according to the following rules:

In the latter case, when adding two ones, the low-order digit overflows and the 1 is transferred to the high-order digit. Overflow occurs if the sum is equal to the base of the number system (in this case it is the number 2) or greater than it (for the binary number system this is not relevant).

For example, let’s add any two binary numbers:

Subtraction

Subtraction of single-digit binary numbers is performed according to the following rules:

0 - 1 = (loan from high rank) 1

Multiplication

Multiplication of single-digit binary numbers is performed according to the following rules:

Division

Division is performed in the same way as in the decimal number system:

Example 1. Find X if To transform the left side of the equality, we successively use De Morgan’s law for logical addition and the law of double negation: According to the distributive law for logical addition: According to the law of exclusion of the third and the law of exclusion of constants: We equate the resulting left side to the right: X = B We finally get: X = B. Example 2. Simplify the logical expression Check the correctness of the simplification using the truth tables for the original and resulting logical expression. According to the law of general inversion for logical addition (de Morgan’s first law) and the law of double negation: According to the distributive law for logical addition: According to the law of contradiction: According to the law of idempotency We substitute the values ​​and, using the commutative law and grouping the terms, we get : According to the law of exclusion (gluing) Substitute the values ​​and get: According to the law of exclusion of constants for logical addition and the law of idempotency: Substitute the values ​​and get: According to the distributive law for logical multiplication: According to the law of exclusion of the third: Substitute the values ​​and finally get: 2 Logical foundations of a computer A discrete converter, which, after processing the input binary signals, produces an output signal that is the value of one of the logical operations, is called a logical element. Below are the symbols (circuits) of basic logical elements that implement logical multiplication (conjunctor), logical addition (disjunctor) and negation (inverter). Rice. 3.1. Conjunctor, disjunctor and inverter Computer devices (adders in the processor, memory cells in RAM, etc.) are built on the basis of basic logical elements. Example 3. For a given logical function F(A, B) = =B&АÚB&A, construct a logical circuit. The construction must begin with a logical operation, which must be performed last. In this case, such an operation is logical addition, therefore, there must be a disjunctor at the output of the logical circuit. Signals are supplied to it from two connectors, which in turn are supplied with one normal and one inverted input signal (from inverters). Example 4. A logic circuit has two inputs X and Y. Determine the logical functions F1(X,Y) and F2(X,Y), which are implemented at its two outputs. The function F1(X,Y) is implemented at the output of the first conjunctor, that is, F1(X,Y) = X&Y. At the same time, the signal from the connector is fed to the input of the inverter, at the output of which the X&Y signal is realized, which, in turn, is fed to one of the inputs of the second connector. The signal Xv Y from the disjunctor is supplied to the other input of the second conjunctor, therefore, the function F2(X,Y) = X&Y&,(XvY). Let's consider a scheme for adding two n-bit binary numbers. When adding the digits of the i-ro digit, ai and bi are added, as well as Pi-1 - the transfer from the i-1 digit. The result will be st - the sum and Pi - the transfer to the most significant digit. Thus, a one-bit binary adder is a device with three inputs and two outputs. Example 3.15. Construct a truth table for a one-bit binary adder using the table for adding binary numbers. Trigger. Triggers are used to store information in the computer's RAM, as well as in the internal registers of the processor. The trigger can be in one of two stable states, which allows you to remember, store and read 1 bit of information. The simplest trigger is the .RS trigger. It consists of two NOR gates that implement the F9 logic function (see Table 3.1). The inputs and outputs of the elements are connected by a ring: the output of the first is connected to the input of the second and the output of the second is connected to the input of the first. The trigger has two inputs S (from the English set - installation) and I (from the English reset - reset) and two outputs Q (direct) and Q (inverse). Rice. 2 Logic circuit of an RS flip-flop Example 3.16. Build a table describing the state of the inputs and outputs of the RS flip-flop. If the inputs receive signals R = 0 and S = 0, then the flip-flop is in storage mode; the previously set values ​​are stored at the outputs Q and Q. If a 1 signal is received at the setting input S for a short time, then the flip-flop goes into state 1 and after the signal at the S input becomes 0, the flip-flop will maintain this state, that is, it will store 1. When 1 is applied to the input R, the flip-flop will go to state 0. Applying a logical one to both inputs S and R can lead to an ambiguous result, therefore such a combination of input signals is prohibited. Tasks for independent completion 1. There are 16 logical functions of two variables (see table 3.1). Construct their logic circuits using basic logic gates: conjunctor, disjunctor, and inverter. 2. Prove that the logic circuit considered in Example 3.10 is a one-bit binary half-adder (the carry from the low-order bit is not taken into account). 3. Prove by constructing a truth table that the logical function P = (A&B)v(A&,P0)v(B&P0) determines the transfer to the most significant digit when adding binary numbers (A and B are terms, Po is a transfer from the least significant digit). 4. Prove by constructing a truth table that the logical function S = (AvBvP0)&Pv(A&.B&P0) determines the sum when adding binary numbers (A and B are terms, Po is a carryover from the low-order digit). 5. Construct a logical circuit of a one-bit binary adder. How many basic logic gates are needed to implement a 64-bit binary number adder? 6. How many basic logical elements form the RAM of a modern computer with a capacity of 64 MB? 1. Write down the numbers in expanded form: a) A8=143511; d)A10=143.511; 6)A2=100111; e)A8=0.143511; c)A16=143511; e)A1e=1AZ,5C1. 2. Write down the following numbers in collapsed form: a) A10=9-101+1*10+5"10-1+3-10~2; b) A16=A-161+1-16°+7-16" 1+5-16~2. 3. Are the numbers written correctly in the corresponding number systems: a) A10 = A,234; c) A16=456.46; b)A8=-5678; d)A2=22.2? 4. What minimum base does the number system have if the numbers 127, 222, 111 are written in it? Determine the decimal equivalent of these numbers in the found number system. 5. What is the decimal equivalent of the numbers 101012, 101018 1010116? 6. A three-digit decimal number ends with the digit 3. If this digit is moved two digits to the left, that is, the recording of a new number begins with it, then this new number will be one more than triple the original number. Find the original number. 2.22. A six-digit decimal number begins on the left with the digit 1. If this digit is moved from the first place on the left to the last place on the right, then the value of the resulting number will be three times greater than the original one. Find the original number. 2.23. Which of the numbers 1100112, 1114, 358 and 1B16 is: a) the largest; b) the smallest? 2.27. Is there a triangle whose side lengths are expressed by the numbers 12g, 1116 and 110112? 2.28.What is the largest decimal number that can be written in three digits in binary, octal and hexadecimal number systems? 2.29. “Frivolous” questions. When 2x2=100? When 6x6=44? When 4x4=20? 2.30. Write down the whole decimal numbers belonging to the following numerical intervals: a) ; b) ; V) . 2.31. There are 11,112 girls and 11,002 boys in the class. How many students are there in the class? 2.32. There are 36 students in the class, of which 21 are girls and 15 are boys. In what number system were students counted? 2. 33. There are 100q fruit trees in the garden, of which 33q apple trees, 22q pears, 16q plums and 5q cherries. In what number system are trees counted? 2.34. There were 100q of apples. After each of them was cut in half, there were 1000q halves. In the number system, with what base were they counted? 2.35.I have 100 brothers. The youngest is 1000 years old, and the oldest is 1111 years old. The eldest is in class 1001. Could this be possible? 2.36. Once upon a time there was a pond in the center of which grew one leaf of a water lily. Every day the number of such leaves doubled, and on the tenth day the entire surface of the pond was already filled with lily leaves. How many days did it take to fill half the pond with leaves? How many leaves were there after the ninth day? 2.37.By selecting the powers of the number 2, which add up to a given number, convert the following numbers into the binary number system: a) 5; at 12; e) 32; b) 7; d) 25; f) 33. Check the correctness of the translation using the Advanced Converter program. 2.3. Converting numbers from one number system to another 2.3.1. Translating integers from one number system to another You can formulate an algorithm for converting integers from a system with base p to a system with base q: 1. Express the base of the new number system in digits of the original number system and perform all subsequent actions in the original number system. 2. Consistently divide the given number and the resulting integer quotients by the base of the new number system until we obtain a quotient that is smaller than the divisor. 3. The resulting remainders, which are digits of numbers in the new number system, are brought into accordance with the alphabet of the new number system. 4. Compose a number in the new number system, writing it starting from the last remainder. Example 2.12. Convert the decimal number 17310 to the octal number system: ■ We get: 17310=2558. Example 2.13. Convert the decimal number 17310 to hexadecimal number system: - We get: 17310=AD16. Example 2.14. Convert the decimal number 1110 to the binary number system. We get: 111O=10112. Example 2.15. Sometimes it is more convenient to write the translation algorithm in the form of a table. Let's convert the decimal number 36310 to binary. 2.3.2. Converting fractional numbers from one number system to another You can formulate an algorithm for converting a proper fraction with base p into a fraction with base q: 1. Express the base of the new number system in digits of the original number system and perform all subsequent actions in the original number system. 2. Consistently multiply the given number and the resulting fractional parts of the products by the base of the new system until the fractional part of the product becomes equal to zero or the required accuracy of number representation is achieved. 3. The resulting integer parts of the products, which are digits of the number in the new number system, are brought into accordance with the alphabet of the new number system. 4. Compose the fractional part of the number in the new number system, starting from the integer part of the first product. Example 2.16. Convert the number 0.6562510 to the octal number system. Example 2.17. Convert the number 0.6562510 to hexadecimal number system. Example 2.18. Convert the decimal fraction 0.562510 to the binary number system. Example 2.19. Convert the decimal fraction 0.710 to the binary number system. Obviously, this process can continue indefinitely, giving more and more new signs in the image of the binary equivalent of the number 0.710. So, in four steps we get the number 0.10112, and in seven steps the number 0.10110012, which is a more accurate representation of the number 0.710 in binary, and so on. Such an endless process is terminated at a certain step, when it is believed that the required accuracy of number representation has been obtained. 2.3.3. Translation of arbitrary numbers Translation of arbitrary numbers, that is, numbers containing an integer and a fractional part, is carried out in two stages. The whole part is translated separately, and the fractional part separately. In the final recording of the resulting number, the integer part is separated from the fractional part. Example 2.20. Convert the number 17.2510 to the binary number system. Translating the whole part: Translating the fractional part: Example 2.21. Convert the number 124.2510 to octal. 2.3.4. Converting numbers from a number system with base 2 to a number system with base 2n and back Converting integers - If the base of the q-ary number system is a power of 2, then converting numbers from the q-ary number system to binary and back can be carried out using simpler methods rules. In order to write an integer binary number in the number system with base q = 2", you need to: 1. Divide the binary number from right to left into groups of n digits each. 2. If the last left group has fewer n digits, then it must be add zeros on the left to the required number of digits. 3. Consider each group as an n-bit binary number and write it with the corresponding digit in the number system with base q = 2p. Example 2.22. The number 1011000010001100102 will be converted to the octal number system. We divide the number from right to left into triads and under each of them we write the corresponding octal digit: We get the octal representation of the original number: 5410628. Example 2.23. Let's convert the number 10000000001111100001112 to the hexadecimal number system. We divide the number from right to left into tetrads and under each of them we write the corresponding hexadecimal digit: We get a hexadecimal representation of the original number: 200F8716. Converting fractional numbers. In order to write a fractional binary number in a number system with base q = 2", you need to: 1. Divide the binary number from left to right into groups of n digits each. 2. If the last right group has fewer n digits, then its must be supplemented on the right with zeros to the required number of digits. 3. Consider each group as an n-bit binary number and write it with the corresponding digit in the number system with base q = 2n. Example 2.24. We convert the number 0.101100012 into the octal number system. We split the number on the left to the right into triads and under each of them we write the corresponding octal digit: We obtain an octal representation of the original number: 0.5428. Example 2.25. We convert the number 0.1000000000112 into the hexadecimal number system. We divide the number from left to right into tetrads and write under each of them the corresponding hexadecimal digit: We obtain a hexadecimal representation of the original number: 0.80316 Translation of arbitrary numbers In order to write an arbitrary binary number in the number system with base q - 2n, you need: [ 1. Divide the integer part of a given binary number from right to left, and fractional - from left to right into groups of n digits each. 2. If the last left and/or right groups contain less than n digits, then they must be supplemented on the left and/or right with zeros to the required number of digits. 3. Consider each group as an n-bit binary number and write it with the corresponding digit in the number system with the base q = 2n. Example 2.26. Let's convert the number 111100101.01112 to the octal number system. We divide the integer and fractional parts of the number into triads and under each of them write the corresponding octal digit: We get the octal representation of the original number: 745.34S. Example 2.27. Let's convert the number 11101001000.110100102 to the hexadecimal number system. We divide the integer and fractional parts of the number into tetrads and under each of them write the corresponding hexadecimal digit: We obtain a hexadecimal representation of the original number: 748,D216. Converting numbers from number systems with base q = 2 into the binary system. In order to convert an arbitrary number written in a number system with base q = 2 into the binary number system, you need to replace each digit of this number with its n-digit equivalent in the binary number system . Example 2.28. Let's convert the hexadecimal number 4AC351b into the binary number system. In accordance with the algorithm: i We get: 10010101100001101012. Tasks for independent completion 2.38. Fill out the table, in each row of which the same integer must be written in different number systems. 2.39. Fill out the table, in each row of which the same fractional number must be written in different number systems. 2.40. Fill out the table, in each row of which the same arbitrary number (the number can contain both an integer and a fractional part) should be written in different number systems. 2.4. Arithmetic operations in positional number systems

Arithmetic operations in the binary number system.


Example 2.29. Let's look at some examples of adding binary numbers:

Subtraction. When performing a subtraction operation, the smaller number is always subtracted from the larger number in absolute value and the corresponding sign is placed. In the subtraction table, a 1 with a bar means a loan in the highest rank.


Example 2.31. Let's look at some examples of multiplying binary numbers:

You see that multiplication comes down to shifts of the multiplicand and additions.

Division. The division operation is performed using an algorithm similar to the algorithm for performing the division operation in the decimal number system.


Addition in other number systems. Below is an addition table in the octal number system:

2.42. Arrange the signs of arithmetic operations so that the following equalities are true in the binary system:

Write the answer for each number in the indicated and decimal number systems. 2.44. What number precedes each of the following:

2.45. Write down the integers belonging to the following numerical intervals:

a) in the binary system;

b) in the octal system;

c) in hexadecimal system.

Write the answer for each number in the indicated and decimal number systems.



2.47. Find the arithmetic mean of the following numbers:

2.48.Sum of octal numbers 17 8 + 1700 8 + 170000 3 + 17000000 8 +
+ 1700000000 8 converted to hexadecimal number system.
Find the fifth digit from the left in the number equal to this amount.


Recover the unknown numbers indicated by a question mark in
the following examples on addition and subtraction, having first determined
Le, in what system the numbers are depicted.

Lesson topic: Arithmetic operations in positional number systems.

9th grade

Lesson objectives:

    Didactic: familiarize students with addition, subtraction, multiplication and division in the binary number system and conduct initial development of the skill of performing these actions.

    Educational: develop students' interest in learning new things, show the possibility of a non-standard approach to calculations.

    Developmental: develop attention, rigor of thinking, and reasoning skills.

Lesson structure.

    Organizational moment –1 min.

    Checking your homework using an oral test –15 minutes.

    Homework -2 minutes.

    Solving problems with simultaneous analysis and independent development of material –25 min.

    Summing up the lesson -2 minutes.

DURING THE CLASSES

    Org moment.

    Homework check (oral test) .

The teacher reads the questions sequentially. Students listen carefully to the question without writing it down. Only the answer is recorded, and very briefly. (If you can answer in one word, then only this word is written down).

    What is a number system? (-is a sign system in which numbers are written according to certain rules using signs of a certain alphabet called numbers )

    What number systems do you know?( non-positional and positional )

    What system is called non-positional? (A number is called non-positional if the quantitative equivalent (quantitative value) of a digit in a number does not depend on its position in the notation of the number ).

    What is the base of the positional MSS? (equal to the number of digits that make up its alphabet )

    What mathematical operation should be used to convert an integer from a decimal number to any other? (By division )

    What needs to be done to convert a number from decimal to binary? (Sequentially divide by 2 )

    How many times will the number 11.1 decrease? 2 when moving the comma one place to the left? (2 times )

Now let’s listen to the poem about an extraordinary girl and answer the questions. (The verse sounds )

EXTRAORDINARY GIRL

She was a thousand and one hundred years old
She went to the hundred and first grade,
She carried a hundred books in her briefcase.
This is all true, not nonsense.

When, dusting with a dozen feet,
She walked along the road.
The puppy was always running after her
With one tail, but one hundred-legged.

She caught every sound
With your ten ears,
And ten tanned hands
They held the briefcase and leash.

And ten dark blue eyes
We looked at the world as usual,
But everything will become completely normal,
When will you understand my story?

/ N. Starikov /

And how old was the girl? (12 years ) What class did she go to? (5th grade ) How many arms and legs did she have? (2 arms, 2 legs ) How does a puppy have 100 legs? (4 paws )

After completing the test, the answers are read out loud by the students themselves, a self-test is conducted, and the students give themselves grades.

Criterion:

    10 correct answers (maybe a small mistake) – “5”;

    9 or 8 – “4”;

    7, 6 – “3”;

    the rest are “2”.

II. Homework assignment (2 minutes)

10111 2 - 1011 2 = ? ( 1100 2 )
10111 2 + 1011 2 = ? ( 100010 2 )
10111 2 * 1011 2 = ? ( 11111101 2 ))

III. Working with new material

Arithmetic operations in the binary number system.

Binary number system arithmetic is based on the use of tables for adding, subtracting and multiplying digits. Arithmetic operands are located in the top row and first column of the tables, and the results are at the intersection of columns and rows:

0

1

1

1

Addition.

The binary addition table is extremely simple. Only in one case, when a 1+1 addition is performed, does a transfer to the most significant digit occur.

1001 + 1010 = 10011

1101 + 1011 = 11000

11111 + 1 = 100000

1010011,111 + 11001,11 = 1101101,101

10111 2 + 1001 2 = ? (100000 2 )

Subtraction.

When performing a subtraction operation, the smaller number is always subtracted from the larger number in absolute value, and the corresponding sign is placed. In the subtraction table, a 1 with a bar means a loan in the highest rank. 10111001,1 – 10001101,1 = 101100,0

101011111 – 110101101 = – 1001110

100000 2 - 10111 2 = ? (1001 2 )

Multiplication

The multiplication operation is performed using a multiplication table according to the usual scheme used in the decimal number system with sequential multiplication of the multiplicand by the next digit of the multiplier. 11001 * 1101 = 101000101

11001,01 * 11,01 = 1010010,0001

Multiplication comes down to shifts of the multiplicand and additions.

111 2 * 11 2 = ? (10101 2 )

V. Summing up the lesson

Card for additional student work.

Perform arithmetic operations:

A) 1110 2 + 1001 2 = ? (10111 2 ); 1101 2 + 110 2 = ? (10011 2 );

10101 2 + 1101 2 = ? (100010 2 ); 1011 2 + 101 2 = ? (10000 2 );

101 2 + 11 2 = ? (1000 2 ); 1101 2 + 111 2 = ? (10100 2 );

B) 1110 2 - 1001 2 = ? (101); 10011 2 - 101 2 = ? (1110 2 );