Classic      01/15/2024

Addition tasks in the binary number system. Addition of binary numbers. Converting a number from decimal to binary

home \ Documentation \ For computer science teacher

When using materials from this site - and placing a banner is MANDATORY!!!

Binary arithmetic

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

Mathematics developed in such a way that this particular set became the main one, but decimal arithmetic is not the only one. If we take only five digits, then on their basis we can construct five-digit arithmetic, and from seven digits - seven-digit arithmetic. In areas of knowledge related to computer technology, arithmetic is often used in which numbers are made up of sixteen digits; accordingly, 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 notation 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 third form of notation is most interesting to us now: 2 * 10 2 + 4 * 10 1 + 6 * 10 0 . It is structured as follows:

Our number has three digits. The leading digit "2" is number 3. So it is multiplied by 10 to the second power. The next digit "4" has a serial number of 2 and is multiplied by 10 in the first one. It is already clear that digits are multiplied by ten to the power of one less than the serial number of the digit. Having understood the above, we can write down the general formula for representing a decimal number. Let's be given 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"

The role of the ten is very clearly visible in this recording. Ten is the basis for the formation of numbers. And by the way, it is called “the base of the number system,” and the number system itself 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 it couldn’t be 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 translation is given by our way of writing numbers. Let's 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

Let's 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). A slight inconvenience of the binary system is immediately visible. The same number, which is written in the decimal system with one digit in the binary system, requires four digits for its recording. But this is the price for simplicity (nothing comes for free). But the binary system gives a huge gain in arithmetic operations. And we will see this later.

Express the following binary numbers as a decimal.

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

Addition of binary numbers.

The method of column addition is generally the same as for a decimal number. That is, addition is performed bitwise, starting with the least significant digit. If, when adding two digits, the SUM is greater than nine, then the digit = SUM - 10 is written, and the WHOLE PART (SUM / 10) is added in the most significant digit. (Add a couple of numbers in a column, remember how this is done.) The same with a binary number. Add one by one, starting with the lowest digit. If the result is more than 1, then 1 is written down and 1 is added to the most significant digit (they say “off the top of my head”).

Let's do the example: 10011 + 10001.

First category: 1+1 = 2. We write 0 and 1 as it comes to mind.

Second category: 1+0+1(memorized unit) =2. We write down 0 and 1, it came to mind.

Third category: 0+0+1(memorized unit) = 1. Write 1.

Fourth category 0+0=0. We write 0.

Fifth category 1+1=2. We write down 0 and add 1 to the sixth digit.

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 independent solutions:

a) 11001 +101 =

b) 11001 +11001 =

c) 1001 + 111 =

e) 10011 + 101 =

e) 11011 + 1111 =

e) 11111 + 10011 =

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

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

Step one. 2 2 = 4, this is not enough. Also 2 3 = 8 is not enough, but 2 4 = 16 is already a lot. Therefore, we leave 2 3 =8. 12 - 8 = 4. Now you need to represent it as a power of two 4.

Step two. 4 = 2 2 .

Then our number is 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 notice that each successive power is the largest power of two, which is less than the decomposed number. To consolidate 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. Nearest power of two 2 2 = 4. 7 - 4 = 3

Step 3. Nearest power of two 2 1 = 2. 3 - 2 = 1

Step 4. Nearest power of two 2 0 =1 1 - 1 =0

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

And our desired binary number is 10111

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

As long as the NUMBER is greater than zero, do

NEXT DIGIT = remainder of NUMBER divided by 2

NUMBER = integer part of NUMBER divided by 2

When this algorithm completes its work, the sequence of calculated NEXT 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 methods discussed differ in the order in which the next digits are obtained. In the first method, the first digit received is the most significant digit of the binary number, and in the second method, the first digit received is, on the contrary, the least significant.

Convert decimal numbers to binary in two ways

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

How to convert a fraction to a decimal number.

It is known that any rational number can be represented as a decimal and an 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<В и неправильной если А>IN.

If a rational number is represented by an improper fraction, and the numerator of the fraction is divided by the denominator by a whole, 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.

Rule of accuracy. Suppose you are given a decimal number that can be represented as a decimal fraction with an accuracy of N digits. In order for the corresponding binary number to be of the same precision, it is necessary to write M - signs in it, so that

Now let’s try to get the translation rule, and first let’s look at example 5,401

Solution:

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

Step 1: 2 -2 = 0.25; 0.401 - 0.25 = 0.151. - this 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 thing can be written in this binary number: 0.011. The first fractional digit is zero, this is because in our expansion there is no power of 2 -1.

From the first and second steps it is clear that this representation is not accurate and it may be desirable to continue the expansion. Let's look at the rule. It says that we need so many signs of M 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 closest power of two to this number is 2 -6 = 0.015625; 0.026 - 0.015625 = 0.010375 Now our more accurate binary number is: 0.011001. There are already six 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 closest power of two to this number is 2 -7 = 0.0078125;

0,010375 - 0,0078125 = 0,0025625

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

0,0025625 - 0,001953125 = 0,000609375

The last resulting remainder is less than 2 -10 and if we wanted to continue approximating the original number, 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 is a little more complicated than converting the integer part. Table of powers of two at the end of the lecture.

Now let’s write down the conversion 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 characters.

Algorithm

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

Action 2: Cycle for calculating the digits of the binary representation (digits after zero). The digit number will be denoted by the symbol K.

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

Then we add zero to the binary number

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

Convert decimal numbers to binary

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

Subtracting binary numbers. We will also subtract numbers in 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 one in the place, then it is done in the highest one. Let's solve the following example:

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

Second category 0 -1. One is missing. We occupy it in the senior category. A unit from a senior digit goes into a junior one, like two units (because the senior digit is represented by a two of a higher degree) 2-1 = 1. We write down 1.

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

Let's check the result in the decimal system

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

Another interesting way to perform subtraction involves the concept of two's complement code, which allows you to reduce subtraction to addition. The result of a number in two's complement code is extremely simple: we take the number, replace the zeros with ones, on the contrary, replace the ones with zeros and add one to the least significant digit. For example, 10010, the additional code will be 011011.

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

Example: 34 - 22 = 12

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

The additional code of 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 most significant digit. If we do this, we get 001100. Let’s discard insignificant zeros and get 1100, that is, the example was solved correctly

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

Check by converting the binary result to the decimal number system.

Multiplication in the binary number system.

First, consider the following interesting fact. In order to multiply a binary number by 2 (decimal two is 10 in the binary system), it is enough to add one zero to the left of the number being multiplied.

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 into 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 bitwise. And for each digit of the second multiplier, one zero is added to the right of the first multiplier. Example (not yet in a column):

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

1011 * 1 + 1011 * 0 + 1011 * 100 = 1011 +101100 = 110111 The same 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 =

e) 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 number system.

We have already looked at three actions and I think it is already clear that, in general, actions on binary numbers differ little from actions on decimal numbers. The only difference is that there are two numbers 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 this.

We select 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 larger 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:

We repeat the described operation until the resulting remainder is less than the divisor. When this happens, the number obtained under the line 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 whose first digit is greater than the divisor. This is the four-digit number 1001. It is in bold. Now you need to find a divisor for the selected number. And here we again win in comparison with the decimal system. The fact is that the selected divisor is necessarily a number, and we only have two numbers. Since 1001 is clearly greater than 101, then everything is clear with the divisor: 1. Let’s perform the operation step.

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

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

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

The resulting number 11 is less than 101, so we write the number 0 in the quotient and lower the next number 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 have run out of digits in the dividend, so 10 is the final remainder, and 1110 is the required quotient.

Let's check in decimal numbers

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 is binary arithmetic needed?” Of course, it has already been shown above that writing a number in the binary system significantly simplifies arithmetic operations, but at the same time the recording itself becomes much longer, which reduces the value of the resulting simplification, so it is necessary to look for problems whose solution is much simpler in binary numbers.

Task 1: Retrieving all samples

Very often there are problems in which you need to be able to construct all possible combinations from a given set of objects. For example, this task:

Given a large pile of stones, arrange the stones into two piles so that the mass of the two piles is as equal as possible.

This task can be formulated as follows:

Find a selection 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 lot of tasks of this kind. And they all boil down, as has already been said, to the ability to obtain all possible combinations (hereinafter we will call them samples) from a given set of elements. And now we will look at the general method of obtaining all possible samples using the binary addition operation. Let's start with an example. Let there be a set of three objects. Let's construct all possible samples. We will denote objects 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 the position with the next number is one, then this means that an element with a number equal to this position is present in the selection, and if there is a zero, then the element is not present. For example, sample (0, 1, 0); consists of one element with number 2, and the selection is (1, 1, 0); consists of two elements with numbers 1 and 2.

This example clearly shows that a 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 this. Using this observed pattern, we can construct the following algorithm for obtaining samples.

Algorithm input data

Given a set of objects N - pieces. In what follows we will call this set 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 with 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 in capital letters BINARY

Algorithm

If a BINARY number consists entirely of ones

Then we stop the algorithm

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

Problem 2: Finding large prime numbers

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

Finding large prime numbers is a very important mathematical problem. Large prime numbers are necessary for some encryption algorithms to securely encrypt messages. Moreover, not just large numbers are needed, but very large ones. The larger the number, the more reliable the cipher built on this number.

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

Why? A prime number acts as a key for encryption and decryption. In addition, we know that prime numbers do not appear very often in the series of natural numbers. There are quite a lot of them among the first thousand, then their number begins to quickly decrease. Therefore, if we take a not very large number as the key, the decipherer, using even a not very fast computer, will be able to get to it (by trying out all the simple numbers one after another as a key) in a limited time.

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

Let's say 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 this.

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 prime with a high degree of probability. It turns out this is possible. The mathematician Mersen discovered that numbers of the following form

They 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 Mersen numbers are prime in the same thousand. 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. There are 5 prime numbers for 9 Mersen numbers. As a percentage, this is 5/9*100 = 55.6%. At the same time, for every 1000 first natural numbers, there are only 169 prime numbers. As a percentage, this is 169/1000*100 = 16.9%. That is, in the first thousand, in percentage terms, primes among Mersen numbers are found almost 4 times more often than among simple natural numbers

___________________________________________________________

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 following 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 Mersen numbers are a sequence of ones and this fact itself gives a big gain. Firstly, in the binary number system it is very simple to obtain the next Mersen number, just add one to the next number, and secondly, looking for divisors in the binary system is much easier than in the decimal system.

Quick 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 quite a labor-intensive task. Of course, it is not too difficult to translate small numbers of three or four digits, but for decimal numbers with 5 or more digits this is already difficult. That is, we need a way to quickly convert large decimal numbers into binary.

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

101010 101010 010101 010101

To make it more clear, here is another example with a smaller number. Let's convert the binary representation of the number 235. Divide 235 by 64 with a remainder. We get:

QUANTIATE = 3, binary 11 or 000011

REMAINDER = 43, binary 101011

Then 235 = 11101011. Let's 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 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 one more complex example. The number is 25678425.

Step 1: 25678425 divided by 64

Private = 401225

Remaining = 25 = 011001

Step 2: 401225 divided by 64

Quotient = 6269

Remainder = 9 = 001001

Step 3: 6269 divided by 64

Quotient = 97

Remaining = 61 = 111101

Step 4: 97 divided by 64

Quotient = 1 = 000001

Remaining = 33 = 100001

Number result = 1.100001.111101.001001.011001

In this number, the intermediate results included in it are separated by a dot.

Convert numbers to binary representation:

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

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

  1. Lesson location: 9th grade - 3rd lesson of the section being studied
  2. Topic of the lesson: Arithmetic operations in the binary number system.

Type of lesson: lecture, conversation, independent work.

Lesson objectives:

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

Educational: instilling skills of independence in work, instilling accuracy and discipline.

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

Interdisciplinary connections: Mathematics:

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

Methodological support for the lesson:PowerPoint presentation.

Lesson Plan

  1. Organizational moment (2 min).
  2. Repetition (10)
  3. Explanation of 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. Updating knowledge.We continue to study the topic of the number system and the goal of our lesson today will be to learn how to perform arithmetic operations in the binary number system, namely, we will look at the rule for performing such operations as addition, subtraction, multiplication, division.
  3. Check of knowledge (frontal survey).

Let's remember:

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

4 . Studying new material is accompanied by a presentation

/ Annex 1/

The teacher explains the new topic using the presentation slides, the students take notes and complete the tasks suggested by the teacher in their notebooks.

Of all positional systems, the binary number system is especially simple. Let's look at 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:

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

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

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

Addition

Let's look at examples of addition.

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

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

1011022+111112=?

1110112+110112=?

Subtraction

Independent work of students in notebooks to consolidate material

101101 2 -11111 2 =?

110011 2 -10101 2 =?
Multiplication
Let's look at examples of 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.
Let's look at examples of multiplication
When performing multiplication in example 2, three units 1+1+1=11 are added in the corresponding digit, 1 is written, and the other unit is transferred to the most significant digit.
In the binary number system, the multiplication operation is reduced to shifts of the multiplicand and addition of intermediate results.
Division

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

Let's look at an example of division

Consolidation (students’ independent work using cards is done in a notebook) /Appendix 2/

For students who have 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, and multiplication.

3. Follow these steps:

110010+111,01

11110000111-110110001

10101,101*111

6 Reflection

Today in class the most educational thing for me was...

I was surprised that...

I can apply the knowledge I learned today in class...

7. Lesson summary

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

Slide captions:

Lesson topic: “Arithmetic operations in positional number systems” Informatics teacher Marina Valentinovna FedorchenkoMOU Berezovskaya secondary school from Berezovka Taishet district Irkutsk Region Let us remember: What is called a number system? What is called the base of a number system? What base does the binary number system have? Indicate which the numbers are written with errors and justify the answer: 1238, 30062, 12ААС0920, 1347610 , What minimum base should a number system have if the numbers can be written in it: 10, 21, 201, 1201 What digit ends an even binary number? What digit ends an odd binary number number?
Laplace wrote about his attitude to the binary number system of the great mathematician Leibniz: “In his binary arithmetic, Leibniz saw a prototype of creation. It seemed to him that one represents the divine principle, and zero represents non-existence, and that the Supreme Being creates everything from non-existence in exactly the same way as one and zero in his system express all numbers.” These words highlight the versatility of the two-character alphabet. All positional number systems are “the same”, namely, in all of them arithmetic operations are performed according to the same rules:
the same laws of arithmetic are valid: --commutative (commutative) 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 (m + n) k = m k + n k
the rules of addition, subtraction and multiplication in a column are valid;
the rules for performing arithmetic operations are based on addition and multiplication tables.
Addition in positional number systems Of all the positional systems, the binary number system is especially simple. Let's look at 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: the same ones are valid: commutative, associative, distributive; the rules of addition, subtraction and multiplication by column are valid; the rules for performing arithmetic operations are based on on addition and multiplication tables.
When adding two digits in a column from right to left in the binary number system, as in any positional system, only one can move to the next digit. The result of adding two positive numbers has either the same number of digits as the maximum of the two terms, or one more digit, but this digit can only be one. Let's look at the examples. Solve the examples yourself:
1011012 + 111112
1110112 + 110112
1001100
1010110
When performing a subtraction operation, the smaller number is always subtracted from the larger number in absolute value, and the result is given the corresponding sign.
Subtraction Let's look at examples Examples:
1011012– 111112
1100112– 101012
1110
11110
Multiplication in positional number systems 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. Let's consider examples of multiplication. Let's look at examples Let's look at an example of division
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 number system, learn the tables of addition, subtraction, multiplication.3. Follow the steps:110010+111,0111110000111-11011000110101,101*111 Reflection Today in the lesson the most informative thing for me was...I was surprised that...I can apply the knowledge acquired today in the lesson...

Sections: Computer science

Target: teach students to perform arithmetic operations in the binary number system .
Tasks:
educational:
- repetition and consolidation of students’ knowledge about number systems;
- to develop in schoolchildren the ability to perform correctly arithmetic operations in the binary number system;
developing:
- develop students’ logical thinking;
- develop the cognitive interest of students.

During the classes.

Learning new material.
Addition rules:
0+0=0
0+1=1
1+0=1
1+1=10
Draw students' attention to the fact that when adding two units in the binary number system, the result is 0, and the unit is transferred to the next digit. When adding three units, the result is 1 in the entry, and the unit is transferred to the next digit. (1+1+1=11).

Example 1.
101+10=111

Example 2.
10011+11=1110


1001+11=1100
110+110=1100

Multiplication rules:
0*0=0
0*1=0
1*0=0
1*1=1

Example 1.
101*11=1111

Explanation:
We multiply each digit of the second factor by each digit of the first factor, the results of the products are added together according to the rules of addition in the binary number system. (Mathematics - 3rd grade).

Example 2.
1011*101=110111

Solution:

Students solve the following examples independently:
1001*101=101101
1001*11=11011

Subtraction rules:
0-0=0
1-0=1
1-1=0
0-1=-1
Draw students’ attention to the fact that the “minus” in the last rule means “take rank (1).”

Example 1.
10110-111=1111

Explanation:
Subtraction is done in the same way as in mathematics. If the digit in the minuend is less than the digit of the subtrahend, then for this subtraction it is necessary to occupy the digit (1), because 10-1=1. If there is a 0 to the left of such a subtraction, then we cannot occupy a rank. In this case, we occupy the digit in the minuend of the unit closest to the left of the given subtraction. In this case, all zeros from which we could not occupy a digit must be changed to one, because 0-1=-1. It is advisable to write down all changes in numbers on top of this subtraction. Perform further subtraction with the resulting numbers from above.

Example 2.
100000-11=11101

Students solve the following examples independently:
100010-100=
101011-10111=

Division rule:
Division is performed according to the rules of mathematics, not forgetting that we perform operations in the binary number system.

Example 1.
101101:1001=101

Explanation:
In the quotient, feel free to write the first 1, because a number in the binary system cannot begin with 0. We multiply this 1 by the divisor, and write the result correctly under the dividend, observing the bit depth. We perform subtraction according to the rules of subtraction in the binary number system. We take down the next digit of the dividend and compare the resulting number with the divisor. In this case, the resulting number is less than the divisor; in the quotient we write 0 (otherwise, 1). We take down the next digit of the dividend. We get a number equal to the divisor, write 1 in the quotient, etc.

Example 2.
101010:111=110

Examples for independent solutions:
1001000:1000=1001
111100:1010=110

Homework.
Follow these steps:
1100+1101=
101+101=
1011*101=
111*101=
11011-110=
10001-1110=
1011010:1010=

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.