Addition of binary numbers. Binary arithmetic Performing arithmetic operations on division in computer science

Lesson topic: Arithmetic operations in positional number systems.

Grade 9

Lesson objectives:

    Didactic: introduce students to addition, subtraction, multiplication and division in the binary system and conduct a primary practice of the skill of carrying out these actions.

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

    Developing: develop attention, rigor of thinking, the ability to reason.

Lesson structure.

    Orgmoment -1 min.

    Checking homework with an oral test -15 minutes.

    Homework -2 minutes.

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

    Summing up the lesson -2 minutes.

DURING THE CLASSES

    Organizational moment.

    Checking homework (oral test) .

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

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

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

    What system is called non-positional? (SCH 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 SSC. (equal to the number of digits that make up its alphabet )

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

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

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

Now let's listen to a verse about an extraordinary girl and answer questions. (Sounds like a verse )

EXTRAORDINARY GIRL

She was a thousand and a hundred years old
She went to the one hundred and first class,
I carried a hundred books in my portfolio.
All this is true, not nonsense.

When, dusting with a dozen feet,
She walked along the road.
She was always followed by a puppy
With one tail, but hundred-legged.

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

And ten dark blue eyes
Considered the world habitually,
But everything will become quite normal,
When 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 pronounced aloud by the students themselves, a self-examination is carried out and the students give themselves marks.

Criterion:

    10 correct answers (maybe a small flaw) - “5”;

    9 or 8 - “4”;

    7, 6 – “3”;

    the rest are “2”.

II. Homework (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 system.

The arithmetic of the binary number system is based on the use of tables of addition, subtraction and multiplication of digits. Arithmetic operands are located in the top row and in the 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 addition 1 + 1 is performed, does a transfer to the most significant bit 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, a smaller number is always subtracted from a larger number in absolute value, and the corresponding sign is put. In the subtraction table, a 1 with a bar means a high order loan. 10111001,1 – 10001101,1 = 101100,0

101011111 – 110101101 = – 1001110

100000 2 - 10111 2 = ? (1001 2 )

Multiplication

The multiplication operation is performed using the 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. 11001 * 1101 = 101000101

11001,01 * 11,01 = 1010010,0001

Multiplication is reduced to shifts of the multiplicand and additions.

111 2 * 11 2 = ? (10101 2 )

V. Summing up the lesson

Card for additional work of students.

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 );

Addition. The addition of numbers in the binary number system is based on the addition table of single-digit binary numbers (Table 6).

It is important to pay attention to the fact that when adding two units, a transfer is made to the highest digit. This happens when the value of a number becomes equal to or greater than the base of the number system.

The addition of multi-digit binary numbers is performed in accordance with the above addition table, taking into account possible transfers from lower digits to higher digits. As an example, let's add binary numbers 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 add them:

Subtraction. The subtraction of binary numbers is based on the table of subtraction of single-digit binary numbers (Table 7).

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.

The subtraction of multi-digit binary numbers is implemented in accordance with this table, taking into account possible loans in high-order digits.

For example, let's subtract binary numbers:

Multiplication. Multiplication is based on the multiplication table of single-digit binary numbers (Table 8).

Multiplication of multi-digit binary numbers is carried out in accordance with this 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. Consider an example of binary multiplication

Note: When adding two numbers equal to 1, 0 is obtained in this digit, and the 1st is transferred to the most significant digit.

Example_21: Numbers 101 (2) and 11 (2) are given. Find the sum of these numbers.

where 101 (2) = 5 (10) , 11 (2) = 3 (10) , 1000 (2) = 8 (10) .

Check: 5+3=8.

When subtracting one from 0, a unit is taken from the highest nearest digit, which is different from 0. At the same time, a unit occupied in the highest digit gives 2 units in the least significant digit and one in all digits between the highest and lowest.

Example_22: Numbers 101 (2) and 11 (2) are given. Find the difference between these numbers.

where 101 (2) =5 (10) , 11 (2) =3 (10) , 10 (2) =2 (10) .

Check: 5-3=2.

The multiplication operation is reduced to repeated shift and addition.

Example_23: Numbers 11 (2) and 10 (2) are given. Find the product of these numbers.

where 11 (2) =3 (10) , 10 (2) =2 (10) , 110 (2) =6 (10) .

Check: 3*2=6.

Arithmetic operations in octal number system

When adding two numbers, the sum of which is equal to 8, in this category, 0 is obtained, and the 1st is transferred to the highest order.

Example_24: Numbers 165 (8) and 13 (8) are given. Find the sum of these numbers.

where 165 (8) = 117 (10) , 13 (8) = 11 (10) , 200 (8) = 128 (10) .

When subtracting a larger number from a smaller number, a unit is taken from the highest nearest digit that is different from 0. At the same time, a unit occupied in the highest digit gives 8 in the least significant digit.

Example_25: Numbers 114 (8) and 15 (8) are given. Find the difference between these numbers.

where 114 (8) =76 (10) , 15 (8) =13 (10) , 77 (8) =63 (10) .

Arithmetic operations in hexadecimal number system

When adding two numbers, in the sum equal to 16, 0 is written in this category, and the 1 is transferred to the highest order.

Example_26: Numbers 1B5 (16) and 53 (16) are given. Find the sum of these numbers.

where 1B5 (16) = 437 (10) , 53 (16) = 83 (10) , 208 (16) = 520 (10) .

When subtracting a larger number from a smaller number, a unit is taken from the highest nearest digit other than 0. At the same time, a unit occupied in the highest digit gives 16 in the least significant digit.

Example_27: Numbers 11A (16) and 2C (16) are given. Find the difference between these numbers.

where 11A (16) =282 (10) , 2C (16) =44 (10) , EE (16) =238 (10) .

Computer data encoding

Data in a computer is represented as a code, which consists of ones and zeros in different sequences.

The code– a set of symbols for presenting information. Encoding is the process of presenting information in the form of a code.

Number codes

When performing arithmetic operations in a computer, they use direct, reverse and additional number codes.

Direct code

Straight the code (representation in the form of an absolute value with a sign) of a binary number is the binary number itself, in which all the digits representing its value are written as in mathematical notation, and the sign of the number is written as a binary digit.

Integers can be represented in a computer with or without a sign.

Unsigned integers usually occupy one or two bytes of memory. To store signed integers, one, two, or four bytes are allocated, while the most significant (leftmost) bit is allocated under the sign of the number. If the number is positive, then 0 is written to this bit, if negative, then 1.

Example_28:

1 (10) =0 000 0001 (2) , -1 (10) =1 000 0001 (2)


Positive numbers in the computer are always represented using a direct code. The direct code of the number completely coincides with the entry of the number itself in the cell of the machine. The direct code of a negative number differs from the direct code of the corresponding positive number only in the contents of the sign bit.

The direct code is used when storing numbers in computer memory, as well as when performing multiplication and division operations, but the format for representing numbers in a direct code is inconvenient for use in calculations, since addition and subtraction of positive and negative numbers are performed differently, and therefore it is necessary to analyze sign operand bits. Therefore, the direct code is practically not used when implementing arithmetic operations on integers in the ALU. But negative integers are not represented in the computer with a direct code. Instead of this format, formats for representing numbers in reverse and additional codes have become widespread.

Reverse code

Reverse code of a positive number coincides with a direct one, and when writing a negative number, all its digits, except for the digit representing the sign of the number, are replaced by opposite ones (0 is replaced by 1, and 1 is replaced by 0).

Example_29:

Example_30:

To restore the direct code of a negative number from the reverse code, all digits, except for the digit representing the sign of the number, must be replaced with opposite ones.

Additional code

Additional code of a positive number coincides with the direct one, and the code of a negative number is formed by adding 1 to the inverse code.

Example_31:

Example_32:

Example_33:

For an integer -32 (10), write an additional code.

1. After converting the number 32 (10) into the binary number system, we get:

32 (10) =100000 (2) .

2. The direct code for the positive number 32 (10) is 0010 0000.

3. For a negative number -32 (10), the direct code is 1010 0000.

4. The reverse code of the number -32 (10) is 1101 1111.

5. The additional code of the number -32 (10) is 1110 0000.

Example_34:

The additional code of the number is 0011 1011. Find the value of the number in decimal notation.

1. The first (sign) digit of the number 0 011 1011 is 0, so the number is positive.

2. For a positive number, the additional, inverse and direct codes are the same.

3. The number in the binary system is obtained from the record of the direct code - 111011 (2) (we discard zeros from the highest digits).

4. The number 111011 (2) after being converted to the decimal number system is 59 (10).

Example_35:

The additional code of the number is 1011 1011. Find the value of the number in decimal notation.

1. Sign digit of a number 1 011 1011 is 1, so the number is negative.

2. To determine the reverse code of the number, subtract one from the additional code. The reverse code is 1 011 1010.

3. The direct code is obtained from the reverse by replacing all the binary digits of the number with the opposite ones (1 for 0, 0 for 1). The direct code of the number is 1 100 0101 (in the sign bit we write 1).

4. The number in the binary system is obtained from the record of the direct code - -100 0101 (2).

4. The number -1000101 (2) after conversion to decimal is equal to -69 (10).


Similar information.


home \ Documentation \ For computer science teacher

When using materials from this site - and placement of the banner is MANDATORY!!!

Binary arithmetic

The numbers we are accustomed to using are called decimal and the arithmetic we use is also called decimal. This is because each number can be made up of a set of digits containing 10 characters - digits - "0123456789".

Mathematics developed in such a way that it was this set that became the main one, but decimal arithmetic is not the only one. If we take only five digits, then on their basis we can build five-fold arithmetic, from seven digits - seven-fold. In areas of knowledge related to computer technology, arithmetic is often used in which numbers are made up of sixteen digits, respectively, this arithmetic is called hexadecimal. To understand what a number is in non-decimal arithmetic, we first find out what a number is in decimal arithmetic.

Take, for example, the number 246. This entry means that there are two hundreds, four tens and six ones in the number. Therefore, we can write the following equality:

246 = 200 + 40 + 6 = 2 * 10 2 + 4 * 10 1 + 6 * 10 0

Here, equal signs separate three ways of writing the same number. The most interesting for us now is the third form of writing: 2 * 10 2 + 4 * 10 1 + 6 * 10 0. It is organized as follows:

We have three numbers. The highest digit "2" has the number 3. So it is multiplied by 10 to the second power. The next digit "4" has serial number 2 and is multiplied by 10 in the first one. It can already be seen that the digits are multiplied by ten to the power of one less than the ordinal number of the digit. Having understood what has been said, we can write down the general formula for representing a decimal number. Let there be a number with N digits. We will denote the i-th digit by a i. Then the number can be written in the following form: a n a n-1 ….a 2 a 1 . This is the first form, and the third entry form will look like this:

a n a n-1 ….a 2 a 1 = a n * 10 n-1 + a n-1 * 10 n-2 + …. + a 2 * 10 1 + a 1 * 10 0

where a i is a character from the set "0123456789"

In this entry, the role of ten is very clearly visible. Ten is the basis for the formation of the number. And by the way, it is called "the base of the number system", and the number system itself, which is why it is called "decimal". Of course, the number ten does not have any special properties. We can easily replace ten with any other number. For example, a number in the five-digit number system can be written like this:

a n a n-1 ….a 2 a 1 = a n * 5 n-1 + a n-1 * 5 n-2 + …. + a 2 * 5 1 + a 1 * 5 0

where a i is a character from the set "01234"

In general, we replace 10 with any other number and get a completely different number system and different arithmetic. The simplest arithmetic is obtained if 10 is replaced by 2. The resulting number system is called binary and the number in it is defined as follows:

a n a n-1 ….a 2 a 1 = a n * 2 n-1 + a n-1 * 2 n-2 + …. + a 2 * 2 1 + a 1 * 2 0

where a i is a character from the set "01"

This system is the simplest of all possible, since in it any number is formed only from two digits 0 and 1. It is clear that there is nowhere simpler. Examples of binary numbers: 10, 111, 101.

Very important question. Can a binary number be represented as a decimal number and vice versa, can a decimal number be represented as a binary number.

Binary to decimal. It's very simple. The method of such a translation gives our way of writing numbers. Take, for example, the following binary number 1011. Let's expand it into powers of two. We get the following:

1011 = 1 * 2 3 + 0 * 2 2 + 1 * 2 1 + 1 * 2 0

We perform all the recorded actions and get:

1 * 2 3 + 0 * 2 2 + 1 * 2 1 + 1 * 2 0 = 8 + 0+ 2 + 1 = 11. Thus, we get that 1011 (binary) = 11 (decimal). You can immediately see a slight inconvenience of the binary system. The same number, which, in the decimal system, is written with one character in the binary system, requires four characters for its recording. But this is a price for simplicity (nothing happens for free). But the binary system gives a huge gain in arithmetic operations. And then we will see it.

Express the following binary numbers as a decimal number.

a) 10010 b) 11101 c) 1010 c) 1110 d) 100011 e) 1100111 f) 1001110

Addition of binary numbers.

The method of addition by a column is in general the same as for a decimal number. That is, addition is performed bit by bit, starting with the least significant digit. If the addition of two digits results in a SUM greater than nine, then the number = SUM-10 is written, and the WHOLE PART (SUM / 10) is added to the highest digit. (Add a couple of numbers in a column, remember how this is done.) So it is with a binary number. Add up bit by bit, starting with the lowest digit. If it turns out more than 1, then 1 is written and 1 is added to the most significant digit (they say "it's crazy").

Let's run an example: 10011 + 10001.

First rank: 1+1 = 2. We write down 0 and 1 came to mind.

Second rank: 1+0+1(memorized unit) =2. We write down 0 and 1 went to mind.

Third rank: 0+0+1(remembered unit) = 1. Write 1.

Fourth rank 0+0=0. We write down 0.

Fifth rank 1+1=2. We write 0 and add 1 to the sixth bit.

Let's convert all three numbers to the decimal system and check the correctness of the addition.

10011 = 1*2 4 + 0*2 3 + 0*2 2 + 1*2 1 + 1*2 0 = 16 + 2 + 1 =19

10001 = 1*2 4 + 0*2 3 + 0*2 2 + 0*2 1 + 1*2 0 = 16 + 1 = 17

100100 = 1*2 5 + 0*2 4 + 0*2 3 + 1*2 2 + 0*2 1 + 0*2 0 =32+4=36

17 + 19 = 36 correct equality

Examples for an independent solution:

a) 11001 +101 =

b) 11001 +11001 =

c) 1001 + 111 =

e) 10011 + 101 =

f) 11011 + 1111 =

e) 11111 + 10011 =

How to convert decimal to binary. The next operation is subtraction. But we will deal with this operation a little later, and now we will consider a method for converting a decimal number to binary.

In order to convert a decimal number to binary, it must be expanded in powers of two. But if the expansion in powers of tens is obtained immediately, then how to expand in powers of two requires a little thought. First, let's look at how to do this by the selection method. Let's take the decimal number 12.

Step one. 2 2 \u003d 4, this is not enough. It is also small and 2 3 \u003d 8, and 2 4 \u003d 16 is already a lot. So let's leave 2 3 =8. 12 - 8 = 4. Now you need to represent 4 as a power of two.

Step two. 4 = 2 2 .

Then our number 12 = 2 3 + 2 2 . The highest digit has the number 4, the highest degree = 3, therefore, there must be terms with powers of two 1 and 0. But we don’t need them, so in order to get rid of unnecessary degrees, and leave the necessary ones, we write the number like this: 1 * 2 3 + 1 * 2 2 +0*2 1 + 0*2 0 = 1100 - this is the binary representation of the number 12. It is easy to see that each next power is the largest power of two, which is less than the number to be expanded. To fix the method, let's look at another example. Number 23.

Step 1. The nearest power of two is 2 4 = 16. 23 -16 = 7.

Step 2. The nearest power of two is 2 2 = 4. 7 - 4 = 3

Step 3. The nearest power of two is 2 1 = 2. 3 - 2 = 1

Step 4. The nearest power of two 2 0 =1 1 - 1 =0

We get the following decomposition: 1*2 4 + 0*2 3 +1*2 2 +1*2 1 +1*2 0

And our desired binary number is 10111

The method considered above solves the problem set before it well, but there is a method that is algorithmized much better. The algorithm for this method is written below:

As long as NUMBER is greater than zero do

NEXT DIGIT \u003d remainder of dividing NUMBER by 2

NUMBER = integer part of NUMBER divided by 2

When this algorithm completes its work, the sequence of calculated REGULAR DIGITS will represent a binary number. For example, let's work with the number 19.

Algorithm start NUMBER = 19

NEXT DIGIT = 1

NEXT DIGIT = 1

NEXT DIGIT = 0

NEXT DIGIT = 0

NEXT DIGIT = 1

So, as a result, we have the following number 10011. Note that the two considered methods differ in the order in which the next digits are obtained. In the first method, the first digit received is the highest digit of the binary number, and in the second method, the first digit received, on the contrary, is the lowest.

Convert decimal to binary in two ways

a) 14 b) 29 c) 134 d) 158 f) 1190 g) 2019

How to convert the fractional part to decimal.

It is known that any rational number can be represented as a decimal and ordinary fraction. An ordinary fraction, that is, a fraction of the form A / B, can be regular and improper. A fraction is called proper if A<В и неправильной если А>AT.

If a rational number is represented by an improper fraction, and at the same time the numerator of the fraction is divided by the denominator completely, then this rational number is an integer, in all other cases a fractional part appears. The fractional part is often a very long number and even infinite (an infinite periodic fraction, for example, 20/6), so in the case of the fractional part, we have not just the task of translating one representation into another, but translating with a certain accuracy.

Accuracy rule. Suppose you are given a decimal number that can be represented as a decimal fraction up to N digits. In order for the corresponding binary number to be of the same precision, it is necessary to write M - characters in it, so that

And now let's try to get the translation rule, and first consider the example 5,401

Decision:

We will get the integer part according to the rules already known to us, and it is equal to the binary number 101. And we expand the fractional part in powers of 2.

Step 1: 2 -2 = 0.25; 0.401 - 0.25 = 0.151. is the remainder.

Step 2: Now we need to represent 0.151 as a power of two. Let's do this: 2 -3 = 0.125; 0.151 - 0.125 = 0.026

Thus, the original fractional part can be represented as 2 -2 +2 -3 . The same can be written in such a binary number: 0.011. The first fractional digit is zero, this is because the degree 2 -1 is absent in our expansion.

It is clear from the first and second steps that this representation is not exact and it may be desirable to continue the decomposition. Let's go back to the rule. It says that we need so many signs of M so that 10 3 is less than 2 M. That is, 1000<2 M . То есть в двоичном разложении у нас должно быть не менее десяти знаков, так как 2 9 = 512 и только 2 10 = 1024. Продолжим процесс.

Step 3: Now we are working with the number 0.026. The nearest power of two to this number is 2 -6 \u003d 0.015625; 0.026 - 0.015625 = 0.010375 now our more precise binary number is 0.011001. There are already six decimal places after the decimal point, but this is not enough yet, so we perform one more step.

Step 4: Now we are working with the number 0.010375. The nearest power of two to this number is 2 -7 \u003d 0.0078125;

0,010375 - 0,0078125 = 0,0025625

Step 5: Now we are working with the number 0.0025625. The nearest power of two to this number is 2 -9 \u003d 0.001953125;

0,0025625 - 0,001953125 = 0,000609375

The last resulting remainder is less than 2 -10 and if we wanted to continue approaching the original number, then we would need 2 -11 , but this already exceeds the required accuracy, and therefore the calculations can be stopped and the final binary representation of the fractional part can be written down.

0,401 = 0,011001101

As you can see, converting the fractional part of a decimal number to binary representation is a little more complicated than converting the integer part. Table of powers of two at the end of the lecture.

And now we write the transformation algorithm:

Initial data of the algorithm: Through A we will denote the original proper decimal fraction written in decimal form. Let this fraction contain N signs.

Algorithm

Action 1. Determine the number of required binary characters M from the inequality 10 N< 2 M

Step 2: Calculate the digits of the binary representation (digits after zero). The number of the digit will be denoted by the symbol K.

  1. Digit number = 1
  2. If 2 -K > A

Then we add zero to the notation of the binary number

    • add 1 to binary number
    • A \u003d A - 2 -K
  1. K = K + 1
  2. If K > M
  • then the algorithm is finished.
  • Otherwise, go to point 2.

Convert decimal to binary

a) 3.6 b) 12.0112 c) 0.231 d) 0.121 e) 23.0091

Subtraction of binary numbers. We will also subtract numbers, we will also use a column and the general rule is the same as for decimal numbers, subtraction is performed bit by bit and if there is not enough unit in the bit, then it is engaged in the older one. Let's solve the following example:

First rank. 1 - 0 =1. We write down 1.

Second rank 0-1. Unit missing. We take it in the senior category. One from the highest digit goes to the lowest one, as two units (because the highest digit is represented by a two of a greater degree) 2-1 \u003d 1. We write down 1.

Third rank. We occupied the unit of this digit, so now in digit 0 there is a need to occupy the unit of the most significant digit. 2-1=1. We write down 1.

Let's check the result in decimal system

1101 - 110 = 13 - 6 = 7 (111) True equality.

Another interesting way to perform subtraction is related to the concept of two's complement, which allows you to reduce subtraction to addition. It turns out a number in an additional code is extremely simple, we take a number, replace zeros with ones, vice versa, we replace ones with zeros and add one to the least significant digit. For example, 10010 would be 011011 in the two's complement code.

The two's complement subtraction rule states that subtraction can be replaced by addition if the subtrahend is replaced by a number in the two's complement code.

Example: 34 - 22 = 12

Let's write this example in binary form. 100010 - 10110 = 1100

The additional code for the number 10110 will be like this

01001 + 00001 = 01010. Then the original example can be replaced by addition like this 100010 + 01010 = 101100 Next, you need to discard one unit in the highest order. If we do this, we get 001100. We discard insignificant zeros and get 1100, that is, the example was solved correctly

Do your subtractions. In the usual way and in additional code, having previously converted decimal numbers to binary:

Check by converting the binary result to decimal.

Multiplication in binary number system.

Let's start with the following interesting fact. In order to multiply a binary number by 2 (decimal two is 10 in binary), it is enough to add one zero to the multiplied number on the left.

Example. 10101 * 10 = 101010

Examination.

10101 = 1*2 4 + 0*2 3 + 1*2 2 + 0*2 1 +1*2 0 = 16 + 4 + 1 = 21

101010 =1*2 5 + 0*2 4 + 1*2 3 + 0*2 2 +1*2 1 +0*2 0 = 32 + 8 + 2 = 42

If we remember that any binary number can be expanded in powers of two, then it becomes clear that multiplication in the binary number system is reduced to multiplication by 10 (that is, by decimal 2), and therefore, multiplication is a series of successive shifts. The general rule is that, as with decimal numbers, binary multiplication is performed bit by bit. And for each digit of the second multiplier, one zero is added to the right of the first multiplier. Example (not yet a column):

1011 * 101 This multiplication can be reduced to the sum of three bitwise multiplications:

1011 * 1 + 1011 * 0 + 1011 * 100 \u003d 1011 + 101100 \u003d 110111 The same thing can be written in a column like this:

Examination:

101 = 5 (decimal)

1011 = 11 (decimal)

110111 = 55 (decimal)

5*11 = 55 correct equality

Decide for yourself

a) 1101 * 1110 =

b) 1010 * 110 =

e) 101011 * 1101 =

f) 10010 * 1001 =

Note: By the way, the multiplication table in the binary system consists of only one item 1 * 1 = 1

Division in the binary system.

We have already considered three actions and I think it is already clear that, in general, actions on binary numbers differ little from actions on decimal numbers. The difference appears only in the fact that there are two digits and not ten, but this only simplifies arithmetic operations. The situation is the same with division, but for a better understanding, we will analyze the division algorithm in more detail. Suppose we need to divide two decimal numbers, for example 234 divided by 7. How do we do it.

We allocate to the right (from the most significant digit) such a number of digits that the resulting number is as small as possible and at the same time more than the divisor. 2 is less than the divisor, therefore, the number we need is 23. Then we divide the resulting number by the divisor with a remainder. We get the following result:

The described operation is repeated until the resulting remainder is less than the divisor. When this happens, the number obtained under the bar is the quotient, and the last remainder is the remainder of the operation. So the operation of dividing a binary number is performed in exactly the same way. Let's try

Example: 10010111 / 101

We are looking for a number, from the highest order of which the first would be greater than the divisor. This is the four-digit number 1001. It is shown in bold. Now you need to find a divisor for the selected number. And here we again win in comparison in the decimal system. The fact is that the selected divisor is necessarily a digit, and we have only two digits. Since 1001 is clearly greater than 101, everything is clear with the divisor, this is 1. Let's perform the operation step.

So, the remainder of the operation is 100. This is less than 101, so in order to perform the second division step, you need to add the next digit to 100, this is the number 0. Now we have the following number:

1000 is greater than 101, so in the second step we again add 1 to the private digit and get the following result (to save space, we immediately omit the next digit).

Third step. The resulting number 110 is greater than 101, so at this step we will write it into the quotient 1. It will turn out like this:

The resulting number 11 is less than 101, so we write it in the private digit 0 and lower the next digit down. It turns out like this:

The resulting number is greater than 101, so we write the number 1 into the quotient and perform the actions again. It turns out this picture:

1

0

The resulting remainder 10 is less than 101, but we ran out of digits in the dividend, so 10 is the final remainder, and 1110 is the desired quotient.

Check in decimals

This concludes the description of the simplest arithmetic operations that you need to know in order to use binary arithmetic, and now we will try to answer the question "Why do we need binary arithmetic." Of course, it has already been shown above that writing a number in the binary system greatly simplifies arithmetic operations, but at the same time, the record itself becomes much longer, which reduces the value of the simplification obtained, so it is necessary to look for such problems, the solution of which is much simpler in binary numbers.

Task 1: Getting All Samples

Very often there are tasks in which you need to be able to build all possible combinations from a given set of items. For example, such a task:

Given a large pile of stones, arrange the stones in two piles in such a way that the mass of these two piles is as much as possible the same.

This task can be formulated as follows:

Find a sample of stones from a large pile such that its total mass differs as little as possible from half the mass of the large pile.

There are quite a few tasks of this kind. And all of them come down, as already mentioned, to the ability to get all possible combinations (we will call them selections below) from a given set of elements. And now we will consider a general method for obtaining all possible samples using the binary addition operation. Let's start with an example. Let there be a set of three items. We construct all possible samples. Items will be denoted by serial numbers. That is, there are the following items: 1, 2, 3.

Samples: (0, 0, 1); (0, 1, 0); (0, 1, 1); (100); (1, 0, 1); (1, 1, 0); (1, 1, 1);

If there is one in the position with the next number, then this means that the element with the number equal to this position is present in the selection, and if there is zero, then the element is not present. For example, sample(0, 1, 0); consists of one element with number 2, and the sample is (1, 1, 0); consists of two elements with numbers 1 and 2.

This example clearly shows that the sample can be represented as a binary number. In addition, it is easy to see that all possible one, two and three-digit binary numbers are written above. Let's rewrite them as follows:

001; 010; 011; 100; 101; 110; 111

1; 10; 11; 100; 101; 110; 111

We have received a series of consecutive binary numbers, each of which is obtained from the previous one by adding one. You can check it out. Using this observed regularity, we can construct the following algorithm for obtaining samples.

Initial data of the algorithm

Given a set of items N - pieces. In what follows, we will refer to this set as the set of initial elements. Let's number all the elements of the original set from 1 to N. Let's make a binary number from N insignificant zeros. 0000… 0 N This zero binary number will denote the zero sample from which the sampling process will begin. The digits of a number are counted from right to left, that is, the leftmost digit is the most significant.

Let's agree to denote this binary number with capital letters BINARY

Algorithm

If a BINARY number consists entirely of ones

Then we stop the algorithm

    • We add one to the BINARY number according to the rules of binary arithmetic.
    • From the received BINARY number we compose the next sample, as described above.

Task 2: Finding Large Primes

First, remember that a prime number is a natural number that is only divisible by 1 and itself. Examples of prime numbers: 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31

Finding large primes is a very important mathematical problem. Large prime numbers are needed to securely encrypt messages with some encryption algorithms. And not just large numbers are needed, but very large ones. The larger the number, the more secure the cipher based on that number.

Note. A strong cipher is a cipher that takes a very long time to decrypt.

Why? A prime number plays the role of a key in encryption and decryption. In addition, we know that prime numbers do not occur very often in the series of natural numbers. There are quite a lot of them among the first thousand, then their number begins to decrease rapidly. Therefore, if we take a not very large number as a key, the decryptor, using even a not very fast computer, will be able to get to it (by sorting through all primes one after another as a key) in a limited time.

A fairly reliable code can be obtained if you take a simple one in which, for example, 150 characters. However, finding such a simple one is not so easy. Let us assume that some number A (very large) needs to be tested for primeness. This is the same as looking for its divisors. If we can find divisors between 2 and the square root of A, then it is not prime. Let's estimate the number of numbers that need to be checked for the ability to divide the number A.

Suppose the number A has 150 digits. The square root of it will contain at least 75 characters. To sort through such a number of possible divisors, we need a very powerful computer and a lot of time, which means that the problem is practically unsolvable.

How to deal with it.

Firstly, you can learn to quickly check for the divisibility of one number by another, and secondly, you can try to select the number A in such a way that it is simple with a high degree of probability. It turns out this is possible. The mathematician Mersen discovered that numbers of the following form

Are simple with a high degree of probability.

To understand the phrase written above, let's count how many prime numbers are in the first thousand and how many Mersenne numbers in the same thousand are prime. So the Mersen numbers in the first thousand are as follows:

2 1 - 1 = 1 ; 2 2 -1 = 3 ; 2 3 - 1 = 7 ; 2 4 - 1 = 15; 2 5 - 1 = 31 ; 2 6 -1 = 63;

2 7 - 1 =127 ; 2 8 -1 = 255; 2 9 - 1 = 511;

Prime numbers are marked in bold. In total there are 5 primes for 9 Mersenne numbers. As a percentage, this is 5/9 * 100 \u003d 55.6%. At the same time, there are only 169 primes for the first 1000 natural numbers. As a percentage, this is 169/1000 * 100 = 16.9%. That is, in the first thousand, in percentage terms, primes among Mersenne numbers are found almost 4 times more often than among simply natural numbers.

___________________________________________________________

And now let's take a specific Mersen number, for example 2 4 - 1. Let's write it as a binary number.

2 4 - 1 = 10000 - 1 = 1111

Let's take the next Mersen number 2 5 -1 and write it as a binary number. We get the following:

2 5 -1 = 100000 - 1 = 11111

It is already clear that all Mersenne numbers are a sequence of ones, and this fact alone gives a big gain. Firstly, in the binary system it is very easy to get the next Mersenne number, it is enough to add one to the next number, and secondly, it is much easier to look for divisors in the binary system than in the decimal one.

Fast decimal to binary conversion

One of the main problems with using the binary number system is the difficulty in converting a decimal number to binary. This is a rather laborious task. Of course, it is not too difficult to translate small numbers of three or four digits, but for decimal numbers in which there are 5 or more digits, this is already difficult. That is, we need a way to quickly convert large decimal numbers to binary representation.

This method was invented by the French mathematician Legendre. Let, for example, the number 11183445 be given. We divide it by 64, we get the remainder 21 and the quotient 174741. We divide this number again by 64, we get the remainder 21 and the quotient 2730. Finally, 2730 divided by 64 gives the remainder 42 and the quotient 42 But 64 in binary is 1000000, 21 in binary is 10101, and 42 is 101010, so the original number will be written in binary as follows:

101010 101010 010101 010101

To make it clearer, another example with a smaller number. Let's translate the binary representation of the number 235. Divide 235 by 64 with a remainder. We get:

PRIVATE = 3, binary 11 or 000011

RESOLUTION = 43, binary 101011

Then 235 = 11101011, Check this result:

11101011 = 2 7 + 2 6 + 2 5 + 2 3 + 2 1 + 2 0 = 128+64+32+8+2+1 = 235

Notes:

  1. It is easy to see that the final binary number includes all the remainders and, at the last step, both the remainder and the quotient.
  2. The quotient is written before the remainder.
  3. If the resulting quotient or remainder has less than 6 digits in binary representation (6 zeros contains the binary representation of the number 64 = 1000000), then insignificant zeros are added to it.

And another difficult example. Number 25678425.

Step 1: 25678425 divided by 64

Private = 401225

Remainder = 25 = 011001

Step 2: 401225 divided by 64

Private = 6269

Remainder = 9 = 001001

Step 3: 6269 divided by 64

Private = 97

Remainder = 61 = 111101

Step 4: 97 divided by 64

Private = 1 = 000001

Remainder = 33 = 100001

Number result = 1.100001.111101.001001.011001

In this number, a dot separates the intermediate results included in it.

Convert to binary representation of a number:

APPENDIX: TABLE 1

0,015625

0,0078125

0,00390625

0,001953125

0,0009765625

0,00048828125

0,000244140625

0,0001220703125

0,00006103515625

0,000030517578125

0,0000152587890625

0,00000762939453125

0,000003814697265625

0,0000019073486328125

0,00000095367431640625

0,000000476837158203125

  1. Place of the lesson: 9th grade-3 lesson of the studied section
  2. Lesson topic: Arithmetic operations in the binary system.

Class type: lecture, conversation, independent work.

Lesson objectives:

Didactic: introduce the rules for performing arithmetic operations (addition, multiplication, subtraction) in the binary number system.

Educational: inculcation of skills of independence in work, education of accuracy, discipline.

Developing: development of attention, memory of students, development of the ability to compare the information received.

Interdisciplinary connections: Mathematics:

Educational equipment (equipment) classes:projector, table, task cards.

Methodological support of the lesson:presentation in PowerPoint.

Lesson Plan

  1. Organizational moment (2 min).
  2. Repetition (10)
  3. Explaining new material (15 min)
  4. Consolidation of the material covered (10 min)
  5. homework assignment
  6. Reflection (2 min)
  7. Summing up (2 min)

During the classes

  1. Organizing time
  2. Knowledge update.We continue to study the topic of the number system and the goal of our today's lesson will be to learn how to perform arithmetic operations in the binary number system, namely, we will consider with you the rule for performing operations such as addition, subtraction, multiplication, division.
  3. Knowledge check (frontal survey).

Let's remember:

  1. What is the number system?
  2. What is the base of a number system?
  3. What is the base of the binary number system?
  4. Indicate which numbers are written with errors and justify your answer:
    123
    8, 3006 2, 12ААС09 20, 13476 10,
  5. What is the minimum base the number system should have if the numbers can be written in it: 10, 21, 201, 1201
  6. What is the end of an even binary number?
    What digit ends with an odd binary number?

4 . The study of new material is accompanied by a presentation

/ Appendix 1/

The teacher explains the new topic on the slides of the presentation, the students take notes and complete the tasks proposed by the teacher in the notebook.

Of all the positional systems, the binary number system is especially simple. Consider performing basic arithmetic operations on binary numbers.

All positional number systems are "the same", namely, in all of them arithmetic operations are performed according to the same rules:

one . the same laws of arithmetic are valid: commutative, associative, distributive;

2. the rules of addition, subtraction and multiplication by a column are fair;

3. The rules for performing arithmetic operations are based on addition and multiplication tables.

Addition

Consider addition examples.

When adding a column of two digits from right to left in the binary number system, as in any positional system, only one can go to the next bit.

The result of adding two positive numbers has either the same number of digits as the maximum of the two terms, or one digit more, but this digit can only be one.

1011022+111112=?

1110112+110112=?

Subtraction

Independent work of students in a notebook to consolidate the material

101101 2 -11111 2 =?

110011 2 -10101 2 =?
Multiplication
Consider examples for multiplication.

The multiplication operation is performed using the 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.
Consider multiplication examples
When performing multiplication in example 2, three units are added 1+1+1=11 in the corresponding digit, 1 is written, and the other unit is transferred to the highest digit.
In the binary number system, the operation of multiplication is reduced to shifts of the multiplicand and the addition of intermediate results.
Division

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

Consider the division example

Consolidation (independent work of students on cards is performed in a notebook) / Appendix 2 /

For students who completed independent work in a short period of time, an additional task is offered.

5. Homework

2. Learn the rules for performing arithmetic operations in the binary number system, learn the tables of addition, subtraction, multiplication.

3. Follow these steps:

110010+111,01

11110000111-110110001

10101,101*111

6 Reflection

Today in the lesson the most informative for me was ...

I was surprised that…

I can apply what I learned in class today...

7. Lesson summary

Today we learned how to perform arithmetic operations in the binary number system (grading for the lesson).

Slides captions:

Theme of the lesson: “Arithmetic operations in positional number systems” Computer science teacher Marina Valentinovna Fedorchenko MOU Berezovskaya secondary school with Berezovka Taishet district, Irkutsk Region Let's remember: What is the number system? What is the base of the number system? What is the base of the binary number system? the numbers are written with errors and justify the answer: 1238, 30062, 12AAC0920, 1347610, What is the minimum base the number system should have if numbers can be written in it: 10, 21, 201, 1201 What digit ends with an even binary number? What digit ends with an odd binary number?
Laplace wrote about his attitude to the binary (binary) number system of the great mathematician Leibniz: “In his binary arithmetic, Leibniz saw the prototype of creation. It seemed to him that one represents the divine principle, and zero - non-existence, and that a higher being creates everything from non-existence in exactly the same way as one and zero in his system express all numbers. These words emphasize the universality of the alphabet, which consists of two characters. All positional number systems are “the same”, namely, arithmetic operations are performed in all of them according to the same rules:
the same laws of arithmetic are valid: --commutative (displacement) m + n = n + m m n = n m associative (combinative) (m + n) + k = m + (n + k) = m + n + k (m n) k = m (n k) = m n k distributive (distributive) (m + n) k = m k + n k
the rules of addition, subtraction and multiplication by a column are valid;
the rules for performing arithmetic operations are based on addition and multiplication tables.
Addition in positional number systems Of all positional systems, the binary number system is especially simple. Consider performing basic arithmetic operations on binary numbers. All positional number systems are "the same", namely, arithmetic operations are performed in all of them according to the same rules: the same ones are valid: commutative, associative, distributive; the rules of addition, subtraction and multiplication by a column are valid; the rules for performing arithmetic operations are based on addition and multiplication tables.
When adding a column of two digits from right to left in the binary number system, as in any positional system, only one can go to the next bit. The result of adding two positive numbers has either the same number of digits as the maximum of the two terms, or one digit more, but this digit can only be one. Consider examples Solve examples yourself:
1011012 + 111112
1110112 + 110112
1001100
1010110
When performing a subtraction operation, a smaller number is always subtracted from a larger number in absolute value and the corresponding sign is put on the result.
Subtraction Consider examples Examples:
1011012– 111112
1100112– 101012
1110
11110
Multiplication in positional number systems The multiplication operation is performed using the multiplication table according to the usual scheme (used in the decimal number system) with successive multiplication of the multiplicand by the next digit of the multiplier. Let's consider examples of multiplication. Let's look at the examples Let's look at the division example
Let's solve examples:
11012 1112

111102:1102=
1011011
101
Homework 1.&3.1.22. Learn the rules for performing arithmetic operations in the binary system, learn the tables of addition, subtraction, multiplication.3. Do the following: 110010+111.0111110000111-11011000110101.101*111 Reflection Today in the lesson the most informative for me was ... I was surprised that ... I can apply the knowledge gained today in the lesson ...

Loading...Loading...