Arithmetic in number systems. Arithmetic operations in number systems. Checking homework

Number systems

Number system – a set of techniques and rules for writing numbers in digital signs or symbols.

All number systems can be divided into two classes: positional And non-positional. In the class of positional systems for writing numbers in various systems Numbers use a number of different signs. The number of such characters in positional system calculus is called the basis of the number system. Below is a table containing the names of some positional number systems and a list of signs (digits) from which numbers are formed in them.

Some number systems

Base Notation Signs
Binary 0,1
Trinity 0, 1, 2
Quaternary 0, 1, 2, 3
Fivefold 0, 1, 2, 3, 4
Octal 0, 1, 2, 3, 4, 5, 6, 7
Decimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
duodecimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B
Hexadecimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

In a positional number system, the relative position of a digit in a number is assigned a weight factor, and the number can be represented as the sum of the products of the coefficients by the corresponding power of the base of the number system (weight factor):

A n А n–1 A n–2 ...A 1 A 0 , A –1 A –2 ... =

A n B n + A n-1 B n-1 + ... + A 1 B 1 + A 0 B 0 + A –1 B –1 + A –2 B –2 + ...

(the “,” sign separates the integer part of the number from the fractional part. Thus, the meaning of each sign in the number depends on the position that the sign occupies in the number record. That is why such number systems are called positional).

A positional number system is a system in which the size of a number is determined by the values ​​of the digits included in it and their relative position in the number.

23,45 10 = 2 ⋅ 10 1 + 3 ⋅ 10 0 + 4 ⋅ 10 –1 + 5 ⋅ 10 –2 .

The decimal index at the bottom indicates the base of the number system.

692 10 = 6 ⋅ 10 2 + 9 ⋅ 10 1 + 2 ⋅ 10 0 ;

1101 2 = 1 ⋅ 2 3 + 1 ⋅ 2 2 + 0 ⋅ 2 1 + 1 ⋅ 2 0 = 13 10 ;

112 3 = 1 ⋅ 3 2 + 1 ⋅ 3 1 + 2 ⋅ 3 0 = 14 10 ;

341,5 8 = 3 ⋅ 8 2 + 4 ⋅ 8 1 + 1 ⋅ 8 0 + 5 ⋅ 8 –1 = 225,125 10 ;

A1F,4 16 = A ⋅ 16 2 + 1 ⋅ 16 1 + F ⋅ 16 0 + 4 ⋅ 16 –1 = 2591.625 10.

When working with computers, you have to use several positional number systems in parallel (most often binary, decimal, octal and hexadecimal), so the procedures for converting numbers from one number system to another are of great practical importance. Note that in all of the above examples, the result is a decimal number, and thus the method of converting numbers from any positional number system to decimal has already been demonstrated.



In general, to convert an integer part of a number from the decimal system to the base B system, you need to divide it by B. The remainder will give the least significant digit of the number. The resulting quotient must be again divided by B - the remainder will give the next digit of the number, etc. Divisions continue until the quotient becomes less than the base. The values ​​of the resulting remainders, taken in reverse order, form the desired binary number.

An example of translating an entire part: Convert 25 10 to a binary number.

25 / 2 = 12 with remainder 1,

12 / 2 = 6 with remainder 0,

6 /2 = 3 with remainder 0,

The whole and fractional parts are translated separately. To convert the fractional part, it must be multiplied by B. The integer part of the resulting product will be the first digit (after the decimal point separating the integer part from the fractional part). The fractional part of the product must be multiplied again by B. The integer part of the resulting number will be the next sign, etc.

To convert a fractional part (or a number that has “0” integers), you need to multiply it by 2. The integer part of the product will be the first digit of the number in binary system. Then, discarding the integer part of the result, we multiply again by 2, etc. Note that a finite decimal fraction may well become an infinite (periodic) binary fraction.

An example of converting a fractional part: Convert 0.73 10 to a binary number.

0,73 ⋅ 2 = 1,46 (whole part 1),

0.46 ⋅ 2 = 0.92 (integer part 0),

0.92 ⋅ 2 = 1.84 (integer part 1),

0.84 ⋅ 2 = 1.68 (integer part 1), etc.

Thus: 0.73 10 = 0.1011 2.

Various arithmetic operations can be performed on numbers written in any number system. Arithmetic operations in all positional number systems are performed according to the same rules that are well known to you.



Consider adding two numbers to base ten:

When adding the numbers 6 and 7, the result can be represented as the expression 10 + 3, where 10 is the full base for the decimal number system. Replace 10 (base) with 1 and substitute to the left of the number 3. We get:

6 10 + 7 10 = 13 10 .

Consider adding two base eight numbers:

When adding the numbers 6 and 7, the result can be represented as the expression 8 + 5, where 8 is the full basis for octal system Reckoning. Replace 8 (base) with 1 and substitute to the left of the number 5. We get:

6 8 + 7 8 = 15 8 .

Consider adding two large numbers to base eight:

Addition starts from the least significant digit. So, we represent 4 8 + 6 8 as 8 (base) + 2. Replace 8 (base) with 1 and add this unit to the high-order digits. Next, we add the following digits: 5 8 + 3 8 + 1 8, represent it as 8 + 1, replace 8 (base) with 1 and add it to the most significant digit. Next, we represent 2 8 + 7 8 + 1 8 as 8 (base) + 2, replace 8 (base) with 1 and substitute it to the left of the resulting number (in the position of the most significant digit). Thus it turns out:

254 8 + 736 8 = 1212 8 .

276 8 + 231 8 = 527 8 ,

4A77 16 + BF4 16 = 566B 16,

1100110 2 + 1100111 2 = 11001101 2 .

Other arithmetic operations (subtraction, multiplication and division) are performed similarly in different number systems.

Let's consider multiplication in a “column”, using the example of two numbers of the binary system:

11101 2 101 2

We write the numbers one below the other, in accordance with the ranks. Then we perform a bitwise multiplication of the second factor by the first and write it with a shift to the left, just as when multiplying decimal numbers. It remains to add the “shifted” numbers, taking into account the base of the numbers, in this case binary.

Let's convert the result to base 16.

In the second digit we represent 29 as 16 (base) and 13 (D). Let's replace 16 (base) with 1 and add it to the most significant digit.

In the third digit 96 + 1 = 97. Then imagine 97 as 6 16 (base) and 1. Add 6 to the highest digit.

In the fourth digit, 20 + 6 = 26. Let's imagine 26 as 16 (base) and 10 (A). We move the unit to the highest digit.

With certain skills in working with various number systems, the entry could be immediately imagined as

A
B B
A D

Thus, A31 16 29 16 = 1A1D9 16.

527 8 – 276 8 = 231 8 ,

566B 16 – 4A77 16 = BF4 16,

11001101 2 – 1100110 2 = 1100111 2 ,

276 8 231 8 = 70616 8,

4A77 16 BF4 16 = 37A166C 16,

1100110 2 · 1100111 2 = 10100100001010 2 .

From the point of view of studying the principles of representation and processing of information in a computer, the systems discussed (binary, octal and hexadecimal) are of great interest, although the computer processes data only converted to binary code (binary number system). However, often in order to reduce the number of characters written on paper or entered from a computer keyboard, it is more convenient to use octal or hexadecimal numbers, especially since, as will be shown below, the procedure for mutually converting numbers from each of these systems into binary is very simple - much simpler than translations between any of these three systems and decimal.

Let us represent the numbers of different number systems according to each other:

Decimal Hexadecimal Octal Binary
A
B
C
D
E
F

The table shows that the numbers of the system with base 2, 8 and 16 have periodic patterns. Thus, the eight values ​​of the octal system, that is, (from 0 to 7 or the full base) correspond to three digits ( triads) binary system. Thus, to describe the numbers of one digit of the octal system, exactly three digits of the binary system are required. The same goes for hexadecimal numbers. Only their description requires exactly four digits ( tetrads) binary system.

It follows that to translate any integer binary number to octal, you need to break it down from right to left into groups of 3 digits (the leftmost group can contain less than three binary digits), and then assign each group its octal equivalent.

For example, you need to convert 11011001 2 to octal.

We divide the number into groups of three digits 011 2, 011 2 and 001 2. We substitute the corresponding numbers of the octal system. We get 3 8, 3 8 and 1 8 or 331 8.

11011001 2 = 331 8 .

Reverse transfers are carried out similarly, for example:

Convert AB5D 16 to binary number system.

One by one we replace each symbol of the number AB5D 16 with the corresponding number from the binary system. We get 1010 16, 1011 16, 0101 16 and 1101 16 or 1010101101011101 2.

AB5D 16 = 1010101101011101 2 .

In addition to the positional number systems discussed above, there are those in which the meaning of a sign does not depend on the place it occupies in the number. Such number systems are called non-positional. The most famous example of a non-positional system is Roman. This system uses 7 characters (I, V, X, L, C, D, M), which correspond to the following values:

Rules for writing numbers in Roman numerals: - If big number stands in front of a smaller one, then they add up (the principle of addition); if a smaller number comes before a larger one, then the smaller one is subtracted from the larger one (the principle of subtraction).

The second rule is used to avoid repeating the same number four times. Thus, Roman numerals I, X, C are placed respectively before X, C, M to indicate 9, 90, 900 or before V, L, D to indicate 4, 40, 400.

Examples of writing numbers in Roman numerals:

IV = 5 - 1 = 4 (instead of IIII),

XIX = 10 + 10 - 1 = 19 (instead of XVIIII),

XL = 50 - 10 =40 (instead of XXXX),

XXXIII = 10 + 10 + 10 + 1 + 1 + 1 = 33, etc.

It should be noted that performing even simple arithmetic operations on multi-digit numbers using Roman numerals is very inconvenient. Probably, the complexity of calculations in the Roman system, based on the use of Latin letters, was one of the compelling reasons for replacing it with a more convenient decimal system.

3.1 The base of a number system is called...

A set of techniques and rules for writing numbers in digital signs or symbols

The number of characters used in a particular positional number system

A divisor used when converting numbers from one number system to another

Common factor when converting numbers from one number system to another

3.2 Which number system is not widely used in computer technology

Octal

Binary

Fivefold

Hexadecimal

Arithmetic operations in all positional number systems are performed according to the same rules. To carry out arithmetic operations on numbers represented in different number systems, it is necessary to first convert them into one number system and take into account the fact that the transfer to the next digit during the addition operation and the loan from the highest digit during the subtraction operation are determined by the value of the base of the number system.

Arithmetic operations in the binary number system are based on tables of addition, subtraction and multiplication of single-digit binary numbers.

When adding two units, the digit overflows and the unit is transferred to the highest digit; when subtracting 0–1, a loan is made from the highest digit; in the “Subtraction” table, this loan is designated 1 with a line over the number (Table 3).

Table 3

Below are examples of performing arithmetic operations on numbers represented in various number systems:

Arithmetic operations on integers represented in various number systems are quite simply implemented using the Calculator and MS Excel programs.

1.3. Representing numbers in a computer

Numerical data is processed in a computer using the binary number system. Numbers are stored in computer memory in binary code, that is, as a sequence of zeros and ones, and can be represented in fixed or floating point format.

Integers are stored in memory in fixed-point format. With this format for representing numbers, a memory register consisting of eight memory cells (8 bits) is allocated for storing non-negative integer numbers. Each digit of a memory cell always corresponds to the same digit of the number, and the comma is located to the right after the least significant digit and outside the digit grid. For example, the number 110011012 would be stored in a memory register as follows:

Table 4

The maximum value of a non-negative integer number that can be stored in a register in fixed-point format can be determined from the formula: 2n – 1, where n is the number of digits of the number. The maximum number will be equal to 28 - 1 = 25510 = 111111112 and the minimum 010 = 000000002. Thus, the range of changes in non-negative integer numbers will be from 0 to 25510.

Unlike the decimal system, the binary number system in the computer representation of a binary number does not have symbols indicating the sign of the number: positive (+) or negative (-), therefore, to represent signed integers in the binary system, two number representation formats are used: number value format signed and two's complement format. In the first case, two memory registers (16 bits) are allocated for storing signed integers, and the most significant digit (leftmost) is used as the sign of the number: if the number is positive, then 0 is written to the sign bit, if the number is negative, then 1. For example , the number 53610 = 00000010000110002 will be represented in the memory registers in the following form:

Table 5

and a negative number -53610 = 10000010000110002 in the form:

Table 6

The maximum positive number or minimum negative number in signed number value format (taking into account the representation of one digit per sign) is 2n-1 – 1 = 216-1 – 1 = 215 – 1 = 3276710 = 1111111111111112 and the range of numbers will be from - 3276710 to 32767.

Most often, to represent signed integers in the binary system, the two's complement code format is used, which allows you to replace the arithmetic operation of subtraction in a computer with an addition operation, which significantly simplifies the structure of the microprocessor and increases its performance.

To represent negative integers in this format, two's complement code is used, which is the modulus of a negative number to zero. Converting a negative integer to additional code carried out using the following operations:

1) write the module of the number in direct code in n (n = 16) binary digits;

2) get the reverse code of the number (invert all digits of the number, i.e. replace all ones with zeros, and zeros with ones);

3) add one to the least significant digit to the resulting reverse code.

For example, for the number -53610 in this format, the modulus will be 00000010000110002, the reciprocal code will be 1111110111100111, and the additional code will be 1111110111101000.

It must be remembered that the complement of a positive number is the number itself.

To store signed integers other than the 16-bit computer representation when used two memory registers(this number format is also called the short signed integer format), the medium and long signed integer formats are used. To represent numbers in the mid number format, four registers are used (4 x 8 = 32 bits), and to represent numbers in the long number format, eight registers are used (8 x 8 = 64 bits). The ranges of values ​​for the medium and long number formats will be respectively: -(231 – 1) ... + 231 – 1 and -(263-1) ... + 263 – 1.

Computer representation of numbers in fixed point format has its advantages and disadvantages. TO benefits include the simplicity of representing numbers and algorithms for implementing arithmetic operations; the disadvantages are the finite range of representation of numbers, which may be insufficient for solving many problems of a practical nature (mathematical, economic, physical, etc.).

Real numbers (finite and infinite decimals) are processed and stored in a computer in floating point format. With this number representation format, the position of the decimal point in the entry may change. Any real number K in floating point format can be represented as:

where A is the mantissa of the number; h – base of the number system; p – number order.

Expression (2.7) for the decimal number system will take the form:

for binary -

for octal -

for hexadecimal -

This form of number representation is also called normal . With a change in order, the comma in the number shifts, that is, it seems to float to the left or to the right. Therefore, the normal form of representing numbers is called floating point form. The decimal number 15.5, for example, in floating point format can be represented as: 0.155 102; 1.55 101; 15.5 100; 155.0 10-1; 1550.0 10-2, etc. This recording form decimal number 15.5 floating point is not used when writing computer programs and entering them into a computer (computer input devices perceive only linear data recording). Based on this, expression (2.7) for representing decimal numbers and entering them into the computer is converted to the form

where P is the order of number,

i.e., instead of the base of the number system 10, they write the letter E, instead of a comma, a dot, and the multiplication sign is not placed. Thus, the number 15.5 in floating point and linear format (computer representation) will be written as: 0.155E2; 1.55E1; 15.5E0; 155.0E-1; 1550.0E-2, etc.

Regardless of the number system, any number in floating point form can be represented by an infinite number of numbers. This form of recording is called non-normalized . For an unambiguous representation of floating point numbers, a normalized form of writing a number is used, in which the mantissa of the number must meet the condition

where |A| - the absolute value of the mantissa of the number.

Condition (2.9) means that the mantissa must be a proper fraction and have a non-zero digit after the decimal point, or, in other words, if the mantissa does not have a zero after the decimal point, then the number is called normalized. So, the number 15.5 in normalized form (normalized mantissa) in floating point form will look like this: 0.155 102, i.e. the normalized mantissa will be A = 0.155 and order P = 2, or in the computer representation of the number 0.155E2 .

Floating point numbers have a fixed format and occupy four (32 bits) or eight bytes (64 bits) of computer memory. If a number occupies 32 bits in the computer's memory, then it is a regular precision number; if it is 64 bits, then it is a double precision number. When writing a floating point number, bits are allocated to store the sign of the mantissa, sign of the exponent, mantissa and exponent. The number of digits allocated to the order of the number determines the range of variation of the numbers, and the number of digits allocated to store the mantissa determines the accuracy with which the number is specified.

When performing arithmetic operations (addition and subtraction) on numbers presented in floating point format, the following procedure (algorithm) is implemented:

1) the order of numbers on which arithmetic operations are performed is aligned (the order of a smaller absolute number increases to the order of a larger absolute number, while the mantissa decreases by the same amount);

2) arithmetic operations are performed on the mantissas of numbers;

3) the result obtained is normalized.

Addition and subtraction

In a system with a base, the numbers 0, 1, 2, ..., c - 1 are used to denote zero and the first c-1 natural numbers. To perform the operation of addition and subtraction, a table is compiled for adding single-digit numbers.

Table 1 - Addition in binary system

For example, an addition table in the hexadecimal number system:

Table 2 - Addition in the hexadecimal system

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

For example,

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

Let's look at one example:

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

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

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

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

We sequentially select the terms according to the power of base 7, starting with the lowest, zero, power.

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

For example,

Multiplication and division

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

Table 3 - Multiplication of single-digit numbers

Table 4 - Multiplication in the hexadecimal number system

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

For example,

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

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

For example:


Converting numbers from one number system to another

There are many various ways converting numbers from one number system to another.

Division method

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

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

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

where 1

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

From (1) we get:

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

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

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

Thus, the digit bi in record (2) of the number N is the remainder of dividing the first incomplete quotient N1 by the base h of the new number system. We represent the second incomplete quotient N2 in the form:

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

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

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

Thus, the sequence of numbers is bm, bm-1. . ,b1,b0 in the notation of the number N in the number system with base h is a sequence of remainders of the sequential division of the number N by base h, taken in reverse order.

Let's look at an example: Convert the number 123 to hexadecimal number system:

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

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

Thus, we get that 340227=2333315

Used to work with data coding, i.e. expressing data of one type in terms of data of another type.

Computer technology also has its own system - it’s called binary coding and is based on representing data as a sequence of just two characters: 0 and 1. These characters are called binary digits, in English - binarydigit or, for short, bit

One bit can express two concepts: 0 or 1 (Yes or no, black or white, true or lie and so on.). If the number of bits is increased to two, then four different concepts can be expressed:

Three bits can encode eight different values: 000 001 010 011 100 101 110 111

By increasing the number of bits in a binary coding system by one, we double the number of values ​​that can be expressed in a given system, that is, the general formula looks like:

N=2 m , Where:

N- number of independent coded values;

T- bit depth of binary coding adopted in this system.

Since a bit is such a small unit of measurement, in practice a larger unit is more often used - a byte, equal to eight bits.

Larger derived data units are also used:

Kilobyte (KB) = 1024 bytes = 2 10 bytes;

Megabyte (MB) = 1024 KB = 2 20 bytes;

Gigabyte (GB) = 1024 MB = 2 30 bytes.

Recently, due to the increase in the volume of processed data, such derived units as:

Terabyte (TB) = 1024 GB = 2 40 bytes;

Petabyte (PB) = 1024 TB = 2 50 bytes;

Exabyte (Ebyte) = 1024 PB = 2 60 bytes.

Encoding text information is produced using the American Standard Code for Information Interchange ASCII, which sets character codes from 0 to 127. National standards allocate 1 byte of information per character and include a table of ASCII codes, as well as national alphabet codes with numbers from 128 to 255. Currently There are five different Cyrillic encodings: KOI-8, MS-DOS, Windows, Macintosh and ISO. At the end of the 90s, a new international standard, Unicode, appeared, which allocates not one byte, but two bytes for each character, and therefore it can be used to encode not but various characters.



Basic encoding table ASCII is given in the table.

Color graphics coding is done using a raster, where each point is associated with its color number. In the RGB coding system, the color of each point is represented by the sum of red (Red), green (Green) and blue (Blue). In the CMYK coding system, the color of each point is represented by the sum of cyan (Cyan), magenta (Magenta), yellow (Yellow) and the addition of black (Black, K).

Analog Signal Coding

Historically, the first technological form of receiving, transmitting and storing data was the analog (continuous) representation of an audio, optical, electrical or other signal. To receive such signals, the computer first performs analog-to-digital conversion.

Analog-to-digital conversion involves measuring an analog signal at regular time intervals τ and encoding the measurement result into an n-bit binary word. In this case, a sequence of n-bit binary words is obtained, representing an analog signal with a given accuracy.

The current CD standard uses what is called "16-bit audio with a scan rate of 44 kHz." For the above figure, translated into normal language, this means that the “step length” (t) is equal to 1/44000 s, and the “step height” (δ) is 1/65,536 of the maximum signal volume (since 2 16 = 65,536) . In this case, the frequency range of playback is 0-22 kHz, and the dynamic range is 96 decibels (which is a quality characteristic completely unattainable for magnetic or mechanical sound recording).

Data compression.

The volume of data processed and transmitted is growing rapidly. This is due to the implementation of increasingly complex application processes, the emergence of new information services, and the use of images and sound.

Data compression- a process that reduces the volume of data. Compression allows you to dramatically reduce the amount of memory required to store data and reduce (to an acceptable size) the time it takes to transfer it. Image compression is especially effective. Data compression can be carried out by software, hardware or a combination.

Compression of texts is associated with a more compact layout bytes, encoding characters. This also uses a space repetition counter. As for sound and images, the amount of information representing them depends on the selected quantization step and the number of bits of analog-to-digital conversion. In principle, the same compression methods are used here as in text processing. If text compression occurs without loss of information, then audio and image compression almost always leads to some loss of information. Compression is widely used in data archiving.

Notation– representation of a number by a specific set of symbols. Number systems are:

1. Single (tag or stick system);

2. Non-positional (Roman);

3. Positional (decimal, binary, octal, hexadecimal, etc.).

Positional is a number system in which the quantitative value of each digit depends on its place (position) in the number. The basis A positional number system is an integer that can be raised to a power and is equal to the number of digits in the system.

The binary number system includes an alphabet of two digits: 0 and 1.

The octal number system includes an alphabet of 8 digits: 0, 1, 2, 3, 4, 5, 6 and 7.

The decimal number system includes an alphabet of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

The hexadecimal number system includes an alphabet of 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

A B C D E F

In computer technology, coding is used in the binary number system, i.e. sequence of 0 and 1.

To convert an integer from one number system to another, you need to perform the following algorithm:

1. Express the base of the new number system using the numbers of the original number system.

2. Consistently divide the given number by the base of the new number system until you get a quotient that is less than the divisor.

3. Convert the resulting balances to a new number system.

4. Compose a number from remainders in the new number system, starting with the last remainder.

In general, in a positional SS with base P, any number X can be represented as a polynomial from base P:

Х = а n Р n + a n-1 P n-1 + … + a 1 P 1 + a o P 0 + a -1 P -1 + a -2 P -2 + …+ a -m P -m ,

where the coefficients a i can be any of the P digits used in SS with the base P.

Converting numbers from 10 SS to any other for the integer and fractional parts of a number is carried out using various methods:

a) the whole part of the number and intermediate quotients are divided by the base of the new SS, expressed in 10 SS until the quotient of the division becomes less than the base of the new SS. Actions are performed in 10 SS. The result is the quotients, written in reverse order.

b) the fractional part of the number and the resulting fractional parts of intermediate products are multiplied by the base of the new SS until the specified accuracy is achieved, or “0” is obtained in the fractional part of the intermediate product. The result is entire parts of intermediate works, recorded in the order in which they were received.

Using formula (1), you can convert numbers from any number system to the decimal number system.

Example 1. Convert the number 1011101.001 from binary number system (SS) to decimal SS. Solution:

1 ·2 6 +0 ·2 5 + 1 ·2 4 + 1 ·2 3 + 1 ·2 2 + 0 ·2 1 + 1 ·2 0 + 0 ·2 -1 + 0 ·2 -2 + 1 ·2 -3 =64+16+8+4+1+1/8=93.125

Example 2. Convert the number 1011101.001 from octal number system (SS) to decimal SS. Solution:

Example 3. Convert the number AB572.CDF from hexadecimal number system to decimal SS. Solution:

Here A-replaced by 10, B- at 11, C- at 12, F- by 15.

Converting an 8 (16) number into 2 form - it is enough to replace each digit of this number with the corresponding 3-bit (4-bit) binary number. Discard unnecessary zeros in the high and low digits.

Example 1: convert the number 305.4 8 to binary SS.

(_3_ _0 _ _5 _ , _4 _) 8 = 011000101,100 = 11000101,1 2

Example 2: convert the number 9AF,7 16 to binary СС.

(_9 __ _A __ _F __ , _7 __) 16 = 100110101111,0111 2

1001 1010 1111 0111

To convert the 2nd number to 8 (16) SS proceed as follows: moving from the decimal point to the left and right, divide the binary number into groups of 3 (4) digits, supplementing the leftmost and rightmost groups with zeros if necessary. Each group is then replaced with the corresponding octal (16) digit.

Example 1: convert the number 110100011110100111,1001101 2 to octal SS.

110 100 011 110 100 111,100 110 100 2 = 643647,464 8

Example 2: Convert the number 110100011110100111.1001101 2 to hexadecimal SS.

0011 0100 0111 1010 0111.1001 1010 2 = 347A7.9A 16

Arithmetic operations in all positional number systems, numbers are performed according to the same rules that are well known to you.

Addition. Let's consider adding numbers in the binary number system. It is based on a table for adding single-digit binary numbers:

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

It is important to pay attention to the fact that when adding two units, the digit overflows and is transferred to the most significant digit. A digit overflow occurs when the value of the number in it becomes equal to or greater than the base.

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

Subtraction. Let's look at subtracting binary numbers. It is based on a table for subtracting single-digit binary numbers. When subtracting a larger number (1) from a smaller number (0), a loan is made from the highest digit. In the table, the loan is designated 1 with a line:

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

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

To carry out arithmetic operations on numbers expressed in different number systems, it is necessary to first convert them into the same system.

| Computer Science and Information and Communication Technologies | Lesson planning and lesson materials | 10th grade | Planning lessons for the academic year (FSES) | Arithmetic operations in positional number systems

Lesson 15
§12. Arithmetic operations in positional number systems

Arithmetic operations in positional number systems

Arithmetic operations in positional number systems with base q are performed according to rules similar to the rules in force in the decimal number system.

In elementary school, addition and multiplication tables are used to teach children to count. Similar tables can be compiled for any positional number system.

12.1. Addition of numbers in the number system with base q

Consider examples of addition tables in ternary (Table 3.2), octal (Table 3.4) and hexadecimal (Table 3.3) number systems.

Table 3.2

Addition in ternary number system

Table 3.3

Addition in hexadecimal number system

Table 3.4

Addition in octal number system

q get the amount S two numbers A And B, you need to sum the digits that form them by digits i from right to left:

If a i + b i< q, то s i = a i + b i , старший (i + 1)-й разряд не изменяется;
if a i + b i ≥ q, then s i = a i + b i - q, the most significant (i + 1)th digit is increased by 1.

Examples:

12.2. Subtracting numbers in the base q number system

So that in a number system with a base q get the difference R two numbers A And IN, it is necessary to calculate the differences between the digits forming them by digits i from right to left:

If a i ≥ b i, then r i = a i - b i, the most significant (i + 1)th digit does not change;
if a i< b i , то r i = a i - b i + g, старший (i + 1)-й разряд уменьшается на 1 (выполняется заём в старшем разряде).



2024 wisemotors.ru. How it works. Iron. Mining. Cryptocurrency.