TVs. Consoles. Projectors and accessories. Technologies. Digital TV

Arithmetic foundations of the computer. Arithmetic and logical basics of computer operation processor 6 arithmetic and logical basics of computer operation

To automate work with data that belongs to different types, their presentation form is unified. This can be done by encoding the data on a uniform basis. In everyday life, coding systems such as Morse code, Braille, and maritime signal codes are used. The basic concept of arithmetic is number. Number is an abstract expression of quantity. The computer processes information presented only in numerical form. It operates with codes and numbers represented in some number system.

A number system is a way of representing numbers (the rule for writing and obtaining numbers), using a fixed set of symbols denoting numbers. Based on the way numbers are represented, number systems are divided into positional and non-positional.

Non-positional systems use many symbols to write numbers. The meaning of a symbol does not depend on its location in the number (Roman SS).

Positional number system – when its weight depends on the position of a digit in a number (555 – units, tens, hundreds). Every positional SS is characterized by a base, i.e. the number of digits used to write a number. Any natural number can be taken as the base SS.

10th – uses 10 digits → 0, 1… 9

2nd – 2 digits → 0, 1

People prefer 10th (this is convenient, apparently because since ancient times they have been counting on their fingers).

In computing, the coding system is based on representing data in the binary number system. Computers use a 2nd system because... there are a number of advantages:

To implement it, you need devices with only two stable states (there is current, there is no current). This is more reliable than, for example, 10th;

it is possible to use the apparatus of Boolean algebra;

binary arithmetic is simpler than decimal arithmetic;

representing information using 2 states is more reliable.

Disadvantage: - rapid growth of ranks.

The computer also uses 8th and 16th systems.

The conversion of numbers from 10 to 2 and vice versa is performed by a machine.

When input, information is encoded, when output it is decoded.

Designation of numbers in the 2nd system: 0, 1, 10, 11(3), 100(4), 101(5), 110(6), 111(7), 1000(8), 1001(9), 1010(10 ), etc.

Designation of numbers in the 8th system: 0, 1, 2 ... 7, 10(8), 11(9), 12(10)……17(15), 20(16), 21(17), etc. .

Designation of numbers in the 16th system: 0, 1, 2 ... 9, A(10), B(11),C(12) ... F(15), 10(16), 11(17), etc.

An integer in a positional SS can be represented as:

Aq=an-1qn-1+an-2qn-2+…+a0q0 , where

A – the number itself;

q – base of the number system;

ai – numbers belonging to the alphabet of a given number system;

n – number of integer digits of the number.

Let the number 37510 be given in the decimal system.

Each position occupied by digits is called a number digit. The digits have the names of numbers: units digit (0), tens digit (1), hundreds digit (2). The names determine the weight (012). A number in a positional number system is the sum of the powers of the base multiplied by the corresponding coefficient, which must be one of the digits of the given number system. It is enough to sum up the weights of the unit digits.

37510=5*100+7*101+3*102 = 5+70+300=375

This is called expanding a number into powers of the base.

The numbers of the digits coincide with the exponent.

1011012=1*20+0*21+1*22+1*23+0*24+1*25=1+0+4+8+0+32=4510

101102=0*20+1*21+1*22+0*23+1*24=0+2+4+0+16=2210

1000012=1*20+0*21+0*22+0*23+0*24+1*25=1+32=3310

178=1*81+7*80= 8+1=1510

77648= 7*83+7*82+6*81+4*80 = 3584+448+48+4 =408410

1716= 1*161+7*160= 16+7 = 2310

3AF16=3*162+10*161+15*160=768+160+15=94310

1A16= 1*161+10*160= 16+10 = 2610

The number system that will be used in the computer determines: the speed of calculations, memory capacity, and the complexity of algorithms for performing arithmetic and logical operations.

Algorithm for converting numbers by dividing by the base of the number system: divide the original number by the base of the new SS. Then we divide the resulting quotient again by the base, etc., until the quotient becomes less than the base SS. We write the last quotient and remainders in the reverse order of receipt

Currently, in everyday life, to encode numerical information, a decimal number system with base 10 is used, which uses 10 designation elements: numbers 0, 1, 2, ... 8, 9. The first (minor) digit indicates the number of units, the second - tens, in the third - hundreds, etc.; in other words, in each subsequent digit the weight of the digit coefficient increases by 10 times.

Digital information processing devices use a binary number system with base 2, which uses two designation elements: 0 and 1. The weights of the bits from left to right from the least significant to the most significant ones increase by 2 times, that is, they have the following sequence: 8421. In general, this the sequence looks like:

…2 5 2 4 2 3 2 2 2 1 2 0 ,2 -1 2 -2 2 -3 …

and is used to convert a binary number to a decimal number. For example, the binary number 101011 is equivalent to the decimal number 43:

2 5 ·1+2 4 ·0+2 3 ·1+2 2 ·0+2 1 ·1+2 0 ·1=43

In digital devices, special terms are used to denote units of information of various sizes: bit, byte, kilobyte, megabyte, etc.

Bit or binary digit determines the value of one character in a binary number. For example, the binary number 101 has three bits or three digits. The rightmost digit, with the least weight, is called younger, and the one on the far left, with the greatest weight, is senior.

Byte defines 8-bit unit of information, 1 byte = 23 bits, for example, 10110011 or 01010111, etc., 1 kbyte = 2 10 bytes, 1 MB = 2 10 kbytes = 2 20 bytes.

To represent multi-digit numbers in the binary number system, a large number of binary digits are required. Recording is easier if you use the hexadecimal number system.

The basis hexadecimal system notation is the number 16 = 2 4, which uses 16 notation elements: numbers from 0 to 9 and the letters A, B, C, D, E, F. To convert a binary number to hexadecimal, it is enough to divide the binary number into four-bit groups: the integer part from right to left, fractional - from left to right of the decimal point. Outer groups may be incomplete.

Each binary group is represented by a corresponding hexadecimal character (Table 1). For example, the binary number 0101110000111001 in hexadecimal is expressed as 5C39.

The decimal number system is most convenient for the user. Therefore, many digital devices, working with binary numbers, receive and issue decimal numbers to the user. In this case, binary decimal code is used.

BCD code is formed by replacing each decimal digit of a number with a four-bit binary representation of this digit in binary code (See Table 1). For example, the number 15 is represented as 00010101 BCD (Binary Coded Decimal). In this case, each byte contains two decimal digits. Note that the BCD code in this conversion is not a binary number equivalent to a decimal number.

1.2 Logical foundations of computers

The branch of mathematical logic that studies the relationships between logical variables that have only two values ​​is called algebra of logic. The algebra of logic was developed by the English mathematician J. Boole and is often called Boolean algebra. Logic algebra is the theoretical basis for constructing digital information processing systems. First, based on the laws of logic algebra, a logical equation of the device is developed, which allows you to connect logical elements in such a way that the circuit performs a given logical function.


Table 1 – Number codes from 0 to 15

Decimal number Codes
Binary hexadecimal BCD
0 0000 0 000
1 0001 1 0001
2 0010 2 0010
3 0011 3 0011
4 0100 4 0100
5 0101 5 0101
6 0110 6 0110
7 0111 7 0111
8 1000 8 1000
9 1001 9 1001
10 1010 A 00010000
11 1011 B 00010001
12 1100 C 00010010
13 1101 D 00010011
14 1110 E 00010100
15 1111 F 00010101

1.2.1 Fundamentals of the algebra of logic

Different boolean variables can be linked by functional dependencies. Functional dependencies between logical variables can be described by logical formulas or truth tables.

In general, logical formula a function of two variables is written as: y=f(X 1 , X 2), where X 1 , X 2 - input variables.

IN truth table displays all possible combinations (combinations) of input variables and the corresponding values ​​of the function y, resulting from the execution of some logical operation. With one variable, the complete set consists of four functions, which are shown in Table 2.


Table 2 - Complete set of functions of one variable

X Y1 Y2 Y3 Y4
0 1 0 1 0
1 0 1 1 0

Y1 - Inversion, Y2 - Identical function, Y3 - Absolutely true function and Y4 - Absolutely false function.

Inversion(negation) is one of the basic logical functions used in digital information processing devices.

With two variables, the full set consists of 16 functions, but not all are used in digital devices.

The main logical functions of two variables used in digital information processing devices are: disjunction (logical addition), conjunction (logical multiplication), sum modulo 2 (dissimilarity), Peirce's arrow and Schaeffer's stroke. The symbols of logical operations that implement the above logical functions of one and two variables are given in Table 3.


Table 3 Names and designations of logical operations

The inversion operation can be performed purely arithmetically: and algebraically: From these expressions it follows that the inversion x, i.e. complements x to 1. This is where another name for this operation came from - addition. From here we can conclude that double inversion leads to the original argument, i.e. and it's called the law of double negation.


Table 4 – Truth tables of the main functions of two variables

Disjunction Conjunction Exclusive OR Pierce's arrow Schaeffer's stroke
X1 X2 Y X1 X2 Y X1 X2 Y X1 X2 Y X1 X2 Y
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1
0 1 1 0 1 0 0 1 1 0 1 0 0 1 1
1 0 1 1 0 0 1 0 1 1 0 0 1 0 1
1 1 1 1 1 1 1 1 0 1 1 0 1 1 0

Disjunction. Unlike ordinary arithmetic or algebraic summation, here the presence of two units gives the result one. Therefore, when denoting logical summation, preference should be given to the sign (∨) instead of the sign (+).

The first two rows of the truth table of the disjunction operation ( x 1 =0) determine law of addition with zero: x ∨ 0 = x, and the second two lines (x 1 = 1) - law of addition with unity: x ∨ 1 = 1.

Conjunction. Table 4 convincingly shows the identity of the operations of ordinary and logical multiplications. Therefore, as a sign for logical multiplication, it is possible to use the familiar sign for ordinary multiplication in the form of a dot.

The first two rows of the truth table of the conjunction operation determine law of multiplication by zero: x 0 = 0, and the second two - law of multiplication by one: x·1 = x.

Exclusive OR. The “Exclusive OR” function means the following: a one appears at the output when only one input has a one. If there are two or more ones at the inputs, or if all inputs are zeros, then the output will be zero.

The inscription on the designation of the element EXCLUSIVE OR “=1” (Figure 1, d) just means that the situation is highlighted when there is one and only one unit at the inputs.

This operation is similar to the arithmetic sum operation, but, like other logical operations, without the formation of a carry. That's why it has a different name sum modulo 2 and the notation ⊕, similar to the notation for arithmetic summation.

Pierce's arrow And Schaeffer's touch. These operations are inversions of the operations of disjunction and conjunction and have no special designation.

The considered logical functions are simple or elementary, since the value of their truth does not depend on the truth of any other functions, but depends only on independent variables called arguments.

Digital computing devices use complex logic functions that are developed from elementary functions.

Complex is a logical function whose truth value depends on the truth of other functions. These functions are the arguments to this complex function.

For example, in a complex logical function the arguments are X 1 ∨X 2 and .

1.2.2 Logic elements

To implement logical functions in digital information processing devices, logical elements are used. Symbols of logical elements that implement the functions discussed above are shown in Figure 1.

Figure 1 – UGO of logical elements: a) Inverter, b) OR, c) AND, d) Exclusive OR, e) OR-NOT, f) AND-NOT.


Complex logical functions are implemented on the basis of simple logical elements, by connecting them appropriately to implement a specific analytical function. Functional diagram of a logical device that implements a complex function, given in the previous paragraph is shown in Figure 2.

Figure 2 – Example of implementation of a complex logical function


As can be seen from Figure 2, the logical equation shows from which LEs and with what connections a given logical device can be created.

Since the logical equation and the functional diagram have a one-to-one correspondence, it is advisable to simplify the logical function using the laws of logical algebra and, therefore, reduce the number or change the nomenclature of LEs during its implementation.

1.2.3 Laws and identities of the algebra of logic

The mathematical apparatus of logic algebra allows you to transform a logical expression, replacing it with an equivalent one in order to simplify, reduce the number of elements or replace the element base.

1 Commutative: X ∨ Y = Y ∨ X; X · Y = Y · X.

2 Combinative: X ∨ Y ∨ Z = (X ∨ Y) ∨ Z = X ∨(Y ∨ Z); X Y Z = (X Y) Z = X (Y Z).

3 Idempotencies: X ∨ X = X; X · X = X.

4 Distributive: (X ∨ Y) Z = X Z ∨ Y Z.

5 Double negative: .

6 Law of Duality (De Morgan's Rule):

To transform structural formulas, a number of identities are used:

X ∨ X Y = X; X(X ∨ Y) = X - Absorption rules.

X· Y ∨ X· = X, (X ∨ Y)·(X ∨ ) = X – Gluing rules.

Precedence rules for logical operations.

1 Negation is the logical action of the first stage.

2 Conjunction is a logical action of the second stage.

3 Disjunction is a logical action of the third stage.

If in a logical expression there are actions of different stages, then the first stage is performed first, then the second and only after that the third stage. Any deviation from this order must be indicated by parentheses.

Transcript

1 Ministry of Education and Science of the Russian Federation State educational institution of higher professional education "Pacific State University" Arithmetic fundamentals of computer operation Guidelines for performing laboratory work in computer science for students of all specialties of full-time education Khabarovsk Publishing house TOGU 2012

2 UDC 004(076.5) Arithmetic fundamentals of computer operation: guidelines for performing laboratory work in computer science for students of all areas of full-time education / comp. V. V. Strigunov, N. I. Shadrina. Khabarovsk: Pacific Publishing House. state university, p. The guidelines were compiled at the Department of Computer Science. Includes general information about the arithmetic basics of computer operation, examples of problem solving, and tasks for independent and individual completion. Published in accordance with the decisions of the Department of Computer Science and the Methodological Council of the Faculty of Computer and Basic Sciences. Pacific State University, 2012

3 GENERAL INFORMATION Any computer is designed to process, transform and store data. To perform these functions, the computer must have some way of representing this data. Presentation of data consists of converting them into a form convenient for subsequent processing either by a user or a computer. The form of data presentation is determined by its final purpose. Depending on this, the data has an internal and external representation. In the external view (for users), all data is stored as files. The simplest methods of external data representation are: real and integer numbers (numeric data); sequence of characters (text); image (graphics, drawings, diagrams, photographs). The internal representation of data is determined by the physical principles by which signals are exchanged between computer hardware, the principles of memory organization, and the logic of computer operation. Any data to be processed by a computer is represented as a sequence of two integers, one and zero. This form of representation is called binary. An important concept when representing data in a computer is the number system. NUMERAL SYSTEMS A number system is a set of techniques and rules for representing numbers using symbols that have a certain quantitative value. There are positional and non-positional number systems. A non-positional number system is a system in which the symbols denoting a particular quantity do not change their meaning depending on the location (position) in the image of the number. Writing the number A in a non-positional number system can be represented by the expression: 3

4 A = D 1 + D D n = D, i where D 1, D 2, D n are symbols of the system. A non-positional number system is the simplest system with one symbol (stick). To depict any number in this system, you need to write down the number of sticks equal to the given number. This system is the most ineffective, since the recording form is very cumbersome. The Roman system also belongs to the non-positional system, the alphabet symbols of which are presented below. n i 1 Roman numerals I V X L C D M Value (denoted quantity) So, for example, in the Roman numeral system in the number XXXII (thirty-two), the value of the digit X in any position is equal to ten. Numbers are written in this number system according to the following rules: 1) if the number on the left is less than the number on the right, then the left digit is subtracted from the right (IX: 1<10, следовательно, 10 1 = 9; XС: 10<100, следовательно, = 90); 2) если цифра справа меньше или равна цифре слева, то эти цифры складываются (VII: 5+1+1=7; XXXV: =35). Так, число 1984 в римской системе счисления имеет вид MCMLXXXIV (M 1000, CM 900, LXXX 80, IV 4). В римской системе нельзя записывать подряд 4 одинаковых цифр. В общем случае непозиционные системы счисления характеризуются сложными способами записи чисел и правилами выполнения арифметических операций. Позиционная система счисления это система счисления, в которой значение цифры определяется ее местоположением (позицией) в изображении числа. 4

5 Positional number system alphabet is an ordered set of symbols (digits) (a 0, a 1, a n) used to represent numbers in a given number system. The base of a positional number system is the number of symbols (digits) of the alphabet q = n + 1 used to represent numbers in a given number system. An example of a positional number system is the decimal number system. Her alphabet is (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Base q = 10. For example, in the decimal number system, the number 333 is written using one digit 3, but the meaning of each digit is determined by its location in the number: the first three is the number of hundreds in the number, the second three is the number of tens, the last is the number of units. Any natural number two, three, four, etc. can be taken as the base of the number system. Usually, successive integers from 0 to (q 1) inclusive are taken as the alphabet. In cases where the generally accepted (Arabic) numerals are not enough to designate all the symbols of the alphabet of the number system with base q > 10, alphanumeric designations are used. For example in table. 1 shows the alphabets of some number systems. Table 1 Number system Base Alphabet of the number system Binary 2 0, 1 Ternary 3 0, 1, 3 Quaternary 4 0, 1, 2, 3 Five 0, 1, 2, 3, 4 Octal 8 0, 1, 2, 3, 4, 5, 6, 7 Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Duodenal 12 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F For the positional number system, the equality is true: A q = a n q n + a n -1 q n a 1 q 1 + a 0 q 0 + a -1 q -1 + a -2 q -2 + a -m q -m where A q (A q = a n a n-1 a 1 a 0,a -1 a -2 a -m) any number written in a number system with base q; (1) 5

6 a i digits of the number (i = n, n-1,1,0,-1, -2, -m); n +1 number of integer digits; m number of fractional digits. Equality (1) is called the expanded form of writing a number. Example Write the numbers 386.11 2, 561.42 8, 6ВF,A 16 in expanded form. According to equality (1) we have: 386.15 10 = .11 2 = .423 8 = BF,A 16 = B F A 16-1 In computer technology, binary, octal, and hexadecimal number systems are most widely used. TRANSLATION OF NUMBERS IN POSITIONAL NUMERAL SYSTEMS We present a table for converting the first 16 numbers into various number systems (Table 2) Decimal numbers q = 10 Binary numbers q = 2 Octal numbers q = 8 Table 2 Hexadecimal numbers q = A B C D E F 6

7 Rule Converting numbers into the decimal number system from the number system with base q Conversion into the decimal system of the number A, written in the number system with base q in the form A q = a n a n-1 a 1 a 0,a -1 a -2 a - m is reduced to calculating the value of the polynomial (1) using decimal arithmetic. Examples 1. Convert the number 7A5F 16 to the decimal system. q = 16 n = 3. 7A5F 16 = A F 16 0 = = = Convert the number 1001 to the decimal system. q = 2 n = 3 m = .1101 (2) = = = .5 + 0.0625 = 9, Convert the number 125.03 8 to the decimal system. q = 8 n=2 m= = , = 85, Converting numbers from the decimal number system to the number system with base q The conversion of a real number from the decimal number system to the number system with base q is carried out in two stages. The integer and fractional parts of the number are translated separately, and then when writing the number in the new number system, the integer part is separated from the fractional part by a comma (dot). Rule Converting integers from the decimal number system to the number system with base q To convert an integer A from the decimal number system to the number system with base q, it is necessary to divide A with the remainder (entirely) by number 7

8 lo q, written in decimal system. Then the partial quotient obtained from such division must be divided again with the remainder by q, etc., until the last partial quotient obtained becomes equal to zero. The representation of the number A in the new number system will be a sequence of division remainders, represented by a q-ary digit and written in the reverse order of the order in which they were obtained. EXAMPLES 1. Convert the number to the binary number system. Number Partial Remainder 405:2 = :2 = :2 = :2 = :2 = :2 = 6 0 6:2 = 3 0 3:2 = 1 1 1:2 = 0 1 Answer: = Convert the number to hexadecimal Reckoning. Number Partial Remainder 20959:16 = :16 = :16 = 5 1 5:16 = 0 5 Answer: = 51DF 16. 8

9 Translation of proper fractions from the decimal number system Rule to the number system with base q To convert a fraction from the decimal number system to the number system with base q, it is necessary to sequentially multiply the original fraction and the resulting fractional products by the base of the number system q until you get zero fractional part or the required calculation accuracy will not be achieved. The representation of a fraction in the new number system will be the sequence of the resulting integer parts of the product, written in the order in which they were received. EXAMPLES 1. Convert the number A=0 to the binary number system. Integer part 0, 000 Answer: 0, = 0, Convert the number 74.67 10 to the octal number system accurate to the fifth digit. Let's first convert the integer part of the number into the octal number system, then the fractional part. Number Partial Remainder 74:8 = 9 2 9:8 = 1 1 1:8 = = .67 10 = 0, Answer: 72.67 10 = 112, Integer part 0.56

10 Converting numbers from the binary number system to systems with a base q = 2 n Converting numbers from a binary system to systems with a base equal to a power of two is performed according to simpler rules than with another base. Rule To convert a binary number to a system with base q = 2 n, you need to divide the number to the left and right of the decimal point into groups of n digits each. If there are less than n digits in the first left or last right groups, then they must be padded on the left and right with zeros. Then, for each group consisting of n binary digits, write the corresponding number in the number system q = 2 n. 1. Convert the number to the octal number system. EXAMPLES q = 8 = 2 3 n = 3. We divide the given number from right to left into groups of 3 digits (triads) and write the corresponding numbers in the octal system: = = Number, convert to hexadecimal number system. q = 16 = 2 4, n = 4. We will divide the integer part of the number from right to left, and the fractional part from left to right into groups of 4 digits (tetrads), we will supplement the missing groups with zeros and write the corresponding numbers in the hexadecimal system: , = , = 36E3,D E 3 D 8 10

11 Rule Converting numbers from number systems with base q = 2 n to the binary system To convert a number from a number system with base q = 2 n into the binary system, you need to replace each digit of the number with an equivalent binary number of n digits in length. Examples 1. Convert the number 537.45 8 to the binary number system. q = 8 = 2 3 n = 3. Replace each digit of the number 537.45 8 with a binary number three digits long (n = 3) 536.45 8 = , (5 101, 3 011, 6 110, 4 100, 5 101) 2. Convert the number 5F7,A23 16 to the binary number system. q = 16 = 2 4 n = 4. Replace each digit of the number 5F7,A23 16 with a binary number four digits long (n = 4) 5F7,A23 16 = , (5 0101, F 1111, A 1010,) ARITHMETIC OPERATIONS IN POSITIONAL SYSTEMS NUMULATIONS The rules for performing arithmetic operations for all positional number systems are the same and coincide with the rules for the decimal number system. In this case, you can use addition and multiplication tables for the number system with base q. For q = 2, 8 and 16, the addition and multiplication tables are presented below. a+b q = 2 11 a b a b 0 1 a b

12 a+b q = 8 12 a b a b a b a+b q = 16 a b A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A A B C D E F B B C D E F A C C D E F A 1B D D E F A 1B 1C E E F A 1B 1C 1D F F A 1B 1C 1D 1E a b a b A B C D E F A B C D E F A C E A 1C 1E C F B 1E A 2D C C C C A F E D C B C E 24 2A C E 54 5A E 15 1C 23 2A F 46 4D 54 5B B 24 2D 36 3F A 63 6C 75 7E 87 A 0 A 14 1E C A 64 6E C 96 B 0 B C D E F 9A A5 C 0 C C C C A8 B4 D 0 D 1A E 5B F 9C A9 B6 C3 E 0 E 1C 2A E 8C 9A A8 B6 C4 D2 F 0 F 1E 2D 3C 4B 5A A5 B4 C3 D2 E1

13 Addition If the result of adding two digits in a number system with base q is greater than q (i.e., the resulting number is two-digit), then the most significant digit of the result is 1. Thus, when adding, only one can move to the next digit, and the result of addition can move to any digit will be less than q. The result of adding two positive numbers has the same number of significant digits as the maximum of the two terms, or one more digit, but this digit can only be one. EXAMPLES Add numbers: = .53 8 = 1413, B9, C, 8 16 = B45, E, 3 3 B 9, C, 0 3 B 4 5, E Subtraction If you need to subtract a number from the number a b and a b, then in column b of the addition table we look for the value of the number a. The leftmost digit in the line in which the value of the number a is found will be the result of the subtraction. If a< b, то нужно заимствовать единицу из левого разряда, поэтому в столбце ищем число 1а, и левая цифра в соответствующей строке будет результатом вычитания. П р и м е р ы Выполнить вычитание чисел: ,1 2 = ,73 8 = 57, Е,D ,6 16 = ED,

14 , E, D , 2 5 E D, 7 8 Multiplication Multiplication is performed in a column using the appropriate multiplication and addition tables. Note that in all positional number systems with any base q, multiplication by numbers of the form q m, where m is an integer, is simply reduced to moving the comma multiplied by m digits to the right or left (depending on the sign of m), just as in decimal number system. EXAMPLES Perform multiplication of numbers: = ,4 8 45.3 8 = 56467,B 16 70,D 16 = 2B7D,2F , 4 6 2, B , 3 7 0, D F B 2 D B 7 D, 2 F , 7 4 Division Both multiplication and division require both multiplication and addition tables in the appropriate number system. The division itself is performed using a corner followed by subtraction of the factors. Perform division: : = : 53 8 = ; 14

15 3. 4C98 16: 2B 16 =1C C B B 1 C Binary-decimal number system The binary-decimal number system is widely used in digital devices, when the main part of the operations is associated not with the processing and storage of input information, but with its input and output to what - or indicators with a decimal representation of the results obtained (microcalculators, cash registers, etc.). In the binary-decimal number system, the numbers from 0 to 9 are represented by four-digit binary combinations from 0001 to 1001, i.e. binary equivalents of the first ten hexadecimal numbers (see Table 2). Conversions from BCD to decimal and inverse conversions are performed by directly replacing four binary digits with one decimal digit or inversely replacing them. EXAMPLE Convert a number from BCD to decimal Answer: = Two BCD digits make up 1 byte. Thus, 1 byte can represent values ​​from 0 to 99, rather than from 0 to 255, as with 8-bit binary. By using 1 byte to represent every two decimal digits, binary decimal numbers can be formed with any desired number of decimal places.

16 So, if a number is considered as binary, then its decimal equivalent = several times greater than the decimal equivalent of a BCD number = = DIRECT, REVERSE, COMPLEMENT CODES Integers are stored in a computer in binary format. When entering, the number is written in the decimal number system familiar to us, and the computer converts it to the binary system. To store an integer, a fixed number of bytes are allocated in RAM: one, two, four or eight. Non-negative and negative numbers are stored differently in computer memory. One, most significant, binary digit is allocated to indicate the sign of the number. A zero in the most significant position means that the number being stored is non-negative, a one means that the number is negative. Three forms of coding of integers are used: direct code, reverse code, complementary code. Direct code Rule To represent a number in a direct code of n-digit format, you need to convert the number to the binary number system and pad it with zeros on the left to n digits. Since the most significant digit of a number is allocated for the sign, and the remaining n 1 digits are for significant digits, write 1 in the sign digit if the number is negative, and leave 0 if the number is positive. For example, the format for storing an integer single-byte number is: Sign of the number Binary representation of the number 16

17 Thus, the number 3 10 in the direct code of a single-byte format will be presented in the form: The number 3 10 in the direct code of a single-byte format has the form: Reverse code. Complementary code The use of signed numbers (direct code for representing numbers) adds complexity to the computer structure. In this case, the operation of adding two numbers with different signs must be replaced by the operation of subtracting a smaller value from a larger one and assigning the sign of the larger value to the result. Therefore, in modern computers, as a rule, negative numbers are represented in the form of complement or inverse codes, which, when summing two numbers with different signs, makes it possible to replace subtraction with ordinary addition. Rule To represent a negative number in the reverse code of the n-bit format, you need to write the module of the negative number in the direct code in n binary digits (convert the number to the binary number system and pad it on the left with zeros to n digits). Invert the values ​​of all signs (replace zeros with ones, ones with zeros). Rule To represent a negative number in n-digit format, you need to represent it in reverse code and add 1 to the last digit of the number. 17

18 Note that positive integers in direct, reverse and complement codes are represented in the same way by binary codes with the number 0 in the sign bit. EXAMPLES 1. Find the complementary code in the single-byte format of the number X = 7 10 The number is a positive integer, its complementary code coincides with the direct code. Let's represent the number in binary and pad it with zeros on the left to 8 digits. Answer: X = Find the inverse code in the single-byte format of the number X = Represent the modulus of the number X in the binary system and pad with zeros on the left up to 8 characters: Invert the values ​​of all signs: Answer: X = Find the complementary code in the double-byte format of the number X = Represent the modulus of the number X in the binary system and add zeros on the left to 16 characters: Invert the values ​​of all characters: , add 1 to the resulting reverse code, we get: Answer: X = The additional code of the number X has the value Find its value in the decimal number system. Because in the first position of the number there is 1, then the desired number will be negative. Subtract 1 (=) from the given value. Let's invert the values ​​of all signs: Let's convert the resulting number to the decimal system = and don't forget that the number is negative. Answer: X = 25. TASKS FOR INDEPENDENT SOLUTION 1. Convert numbers from a given number system to decimal: ; 0, ; F0A9 16 ; 46.05 7; 471,

19 2. Convert the numbers 95 and 568.125 from the decimal number system to binary, octal, hexadecimal. 3. Convert the number to the quaternary number system. 4. Sort the numbers in descending order: 55 7, 55 16. Find the sum and difference of the numbers 11001.11 2 and 1010.011 2 in the binary number system. 6. Find the sum and difference of the numbers 505С 16 and 5А6 16 in the hexadecimal number system. 7. Find the product of the numbers 11 2 and in the binary number system. 8. Find the value of the expression in the binary number system. 9. In the octal number system, a number is represented as Choose the correct representation in the decimal number system. 8 4, 8 5, Find the value of a number in hexadecimal and octal number systems. 11. In what number system were the actions performed: = 201? 12. In what number system were the actions performed: = 131? 13. Number, convert to octal and hexadecimal number systems. 14. Convert the number 2A 16 to the octal number system. 15. The number 23 x from the number system with base x was converted to the decimal number system and received Find the base of the number system x. 16. The number 135 x was transferred from the number system with base x to the decimal number system and received Find the base of the number system x. 17. The reverse code of the number X has the value Find its value in the decimal number system. 19

20 18. Find the additional code in a single-byte number format Find the additional code for the number X = in a single-byte format. 20. The additional code of the number X has the meaning Find its value in the decimal number system. 21. Three numbers 33, 66, 88 are given in different number systems. We added one to these numbers and got 100 in all number systems. Find the values ​​of all these numbers in the decimal number system. 22. The number in the hexadecimal number system F023A9,12С4 is specified. How will the number change if the decimal point in its representation is moved two places to the left? Three places to the right? INDIVIDUAL TASKS Task 1. Convert these numbers from the decimal number system to binary, octal and hexadecimal number systems. Convert real numbers to the new number system accurate to the fourth digit. Number option 78.15 57.17 82.21 33.38 25.27 85.14 20.18 90.42 48.28 55.49 Number option 76.45 43.86 77.35 71.41 30.19 92 ,24 74.23 30.18 41.29 36.73 Task 2. Convert numbers from the given number system to decimal. Option Numbers A2C, E, F, A 16 3FD, E 16 19F, C 16 16D,

21 Option Numbers,B 16 14F, A, C,7 16 2A3,B 16 3AB,A 16 1BA,11 2 Option Numbers,C 16 24D, A,C 16 15C,4 16 2E3,D 16 32B,F ,111 Task 3. Convert these numbers from the decimal number system to binary decimal. Option Numbers Option Numbers Task 4. Convert these numbers from the binary-decimal number system to decimal. Option Numbers Option Numbers Option Numbers

22 Option Numbers Task 5. Write additional number codes in single-byte format. Option Numbers Option Numbers Task 6. Write down integers in the decimal number system if their additional codes are given. Option Additional code Option Additional code Option Additional code Option Additional code

23 LIST OF RECOMMENDED REFERENCES 1. Akulov O. A. Informatics: basic course: textbook. manual for university students / O. A. Akulov, N. V. Medvedev. M.: Omega-L, p. 2. Mogilev A.V. Informatics: textbook. aid for students higher textbook institutions / A. V. Mogilev, N. I. Pak, E. K. Henner. M.: Academy, p. 3. Mogilev A.V. Workshop on computer science: textbook. aid for students higher textbook institutions / A. V. Mogilev, N. I. Pak, E. K. Henner. M.: Academy, p. CONTENTS General information... 3 Number systems... 3 Converting numbers in positional number systems... 6 Converting numbers into a decimal number system from a number system with the base q... 7 Converting numbers from a decimal number system into a number system with a base q... 7 Converting numbers from the binary number system to systems with base q = 2 n.. 10 Converting numbers from number systems with base q = 2 n to the binary system Arithmetic operations in positional number systems Addition Subtraction Multiplication Division Binary-decimal system Numbers Direct, backward, additional codes Tasks for independent solution Individual tasks List of recommended literature

24 ARITHMETICAL BASICS OF COMPUTER OPERATION Methodological instructions for performing laboratory work in computer science for full-time students of all specialties Valery Vitalievich Strigunov Nina Ivanovna Shadrina Editor-in-chief L. A. Suevalova Editor N. G. Petryaeva Signed for printing Format / 16. Writing paper. Times typeface. Digital printing. Conditional oven l. 1.39. Circulation 200 copies. Order Publishing house of the Pacific State University, Khabarovsk, st. Pacific, 136. Department of operational printing of the publishing house of the Pacific State University, Khabarovsk, st. Pacific,


Number systems A number system is a way of writing numbers using a given set of special characters (digits). There are positional and non-positional number systems. In non-positional systems, the weight

Federal Agency for Education State Educational Institution Secondary Professional Education "Vologda Mechanical Engineering College" Number systems Textbook for the disciplines "Computer Science" and "Information Technologies in Professional Activities"

Number systems and computer arithmetic Contents Introduction... 3 I. Coding of numerical information.... 4 1.1. Presentation of numerical information using number systems... 4 1.2. Non-positional systems

Laboratory work 3. Number systems Goal: to master the skills of operating numbers in various number systems. The task is to learn: personal; 1) carry out conversion from the decimal number system to

The concept of a number system Numbers are used to record information about the number of objects. Numbers are written using special sign systems called number systems (s/s). Alphabet

Laboratory work 3 “Arithmetic foundations of computers” Purpose of the work: to study the theoretical foundations and acquire practical skills in transforming the representation of numbers in the number systems used

Ministry of Education and Science of the Russian Federation Federal State Budgetary Educational Institution of Higher Professional Education "Siberian State Industrial University"

Laboratory work 1. Topic: Translation from one number system to another. Goal: learn to convert numbers from one number system to another. Methodical instructions. The number system means

REPRESENTATION OF INFORMATION IN A COMPUTER Information in a computer is encoded, as a rule, in a binary or binary-decimal number system. A number system is a way of naming and representing numbers using

Topic 7. Presentation of information in a computer. Units of information. Bit - (bit-biry digit - binary digit) the smallest unit of information - the amount of it necessary to distinguish between two equally probable events.

Encoding Numerical Information Number systems are used to represent numbers. The number system is a sign system in which numbers are written according to certain rules using symbols

CODING NUMERICAL INFORMATION IN DIFFERENT NUMERAL SYSTEMS 1 Concept of basic number systems A number system is a way of representing any number using some alphabet of symbols,

Number systems Nowadays, people come across numbers all the time. Since childhood, we have all been familiar with the generally accepted notation of numbers using Arabic numerals. However, this recording method was far from being used

Practical work. Forms for representing numerical information on a computer. Part I. Number systems. A number system is a way of representing any number using some alphabet.

Municipal budgetary educational institution “Secondary school 6”, Kurchatov, Kursk region NUMERICAL SYSTEMS Compiled by: computer science teacher Marina Vyacheslavovna Matveychuk

Lecture 5 Topic: “Information coding. Number systems" Objectives: To systematize and generalize students' knowledge obtained while studying the topic "Arithmetic operations in positional number systems"; Develop

MINISTRY OF EDUCATION AND SCIENCE OF THE RUSSIAN FEDERATION FEDERAL STATE BUDGETARY EDUCATIONAL INSTITUTION OF HIGHER PROFESSIONAL EDUCATION “DON STATE TECHNICAL UNIVERSITY”

Problems involving converting numbers from one number system to another. A number system is a set of techniques and rules by which numbers are written and read. There are positional and non-positional systems

LECTURE 4 NUMERAL SYSTEMS 1. Positional and non-positional number systems 2. Methods for converting numbers 3. Binary arithmetic 1. Positional and non-positional number systems Definition 1. Number system

Number systems A number system is a way of describing numbers using signs of a certain alphabet according to known rules. Positional number systems In a positional number system, the value of a digit depends

Arithmetic foundations of computers (Based on materials from http://book.kbsu.ru/) 1. What is a number system? A number system is a set of techniques and rules by which numbers are written and read. There are

Coding is the process of presenting information (messages) in the form of a code. The entire set of symbols used for coding is called the coding alphabet. The number system is a set of techniques

Lecture 5 Basics of presenting information in digital machines Positional number systems A number system is a set of techniques and rules for writing numbers in digital signs. Any intended

Introduction to number systems A.A. Vylitok The number system is a way of writing numbers using a given set of special characters (digits). There are positional and non-positional number systems. In non-positional

NUMERAL SYSTEMS When it comes to measuring something quantitatively, people have to use one number system or another. There are many number systems, some are more common,

Federal State Budgetary Educational Institution of Higher Professional Education "Vyatka State Humanitarian University" Additional training for schoolchildren in the discipline

Lecture: Concept of computer architecture. Number systems. Goal: to form primary ideas about the discipline being read, to consider the possibilities of converting numbers into different number systems, and so on

Measuring information Example. You find yourself in a country with an unfamiliar language and you need to get to the hotel. You want to get on the bus, there are two of them in front of you. You approach the driver of one of them and show

Number systems. Binary number system. 1 The number system is a sign system that determines the way of writing (representing) numbers. All number systems that existed before and that are in use

Number systems A number system is a way of writing numbers using a given set of special characters (digits). In computing, positional number systems are used, in which the value of a digit is

Chapter 13. DIGITAL AND COMBINATIONAL ELECTRONIC DEVICES 13.1. BINARY NUMERAL SYSTEM A number system is a set of symbols (digits) and methods of writing numbers. Depending on the recording method

POSITIONAL NUMERAL SYSTEMS There are many ways to represent numbers. In any case, a number is represented by a symbol or a group of symbols (a word) of some alphabet. We will call such symbols

Ministry of Agriculture of the Russian Federation Federal State Educational Institution of Higher Professional Education "Michurinsky State Agrarian University" Protocol 10 APPROVED

Contents Brief theoretical information... 3 Binary number system... 5 Octal and hexadecimal number systems... 5 Converting a number from one positional number system to another... 6

On the topic Definition. Non-positional and positional number systems Expanded form of writing a number in the positional number system Binary number system. Number equivalent table. Converting numbers between

Rules for converting numbers from one number system to another Transfer of numbers from one number system to another is an important part of machine arithmetic. Let's consider the basic rules of translation. 1. For translation

Topic 1 Number systems Theory First we need to remember what number systems are. A number system (SS) is a set of rules for recording numbers using a finite set of symbols (digits). Systems

Appendix 1 Practical work for Chapter 2 “Representation of information on a computer” Practical work for paragraph 2.1 Example 2.1. Present the numbers 2466.675 10, 1011.11 2 as an expansion to powers of the base. For decimal

Lecture 4. Arithmetic foundations of computers 4.1. What is a number system? A number system is a way of writing numbers using a given set of special characters (digits). There are positional and

Laboratory work. Topic: “Number systems” Purpose of work: Introduction to number systems. Converting a number from the binary number system to the octal and hexadecimal systems and vice versa. Translation

Briefly about the main topic: Number systems Number systems are a way of representing numbers and the corresponding rules for operating numbers. Various number systems that existed before

PRACTICAL WORK "MATHEMATICAL FUNDAMENTALS OF COMPUTER" Purpose of the work: To study number systems, rules for converting from one number system to another, forms of representing numbers and performing arithmetic operations

Ministry of Education and Science of the Russian Federation Federal Agency for Education Saratov State Technical University Balakovo Institute of Engineering, Technology and Management SYSTEMS

Solving problems on the topic “Representing numbers in a computer” Types of problems: 1. Integers. Representation of numbers in fixed point format. 2. Fractional numbers. Representation of numbers in floating point format.

Laboratory work 1 Number systems Purpose of the work: to master the techniques of converting numbers from one number system to another Theoretical information A number system is understood as a way of representing numbers

Number systems Lecture plan P. 1. The concept of a number system. Types of number systems.... 1 P. 2. Basic definitions of a positional number system.... 1 P. 3. Converting numbers from one number system

Given: a EA6, b. Which of the numbers C, written in the binary number system, satisfies the inequality a C b?) 000) 00) 000) 00 Solution: When converting a and b into binary representation, we get: a=ea 6

Solving problems on the topic “Representing numbers in a computer.” Types of tasks. 1. Integers. Representation of numbers in fixed point format. 2. Fractional numbers. Representation of numbers in floating format

Given: a EA6, b 3 8. Which of the numbers C, written in the binary number system, satisfies the inequality a C b?) 000) 00 3) 000) 00 Solution: When converting a and b into binary representation, we obtain: a= ea

Federal State Budgetary Institution of Higher Professional Education "Saratov State Technical University named after Yu.A. Gagarin" NUMERAL SYSTEMS. BINARY CODING

1 NUMERAL SYSTEMS AND REPRESENTATION OF INFORMATION IN COMPUTER 1.1 Concept of basic number systems A number system is a way of representing any number using some alphabet of symbols,

Informatics. Lecture 2 Number systems, binary arithmetic. Number is an abstraction used to describe the quantitative characteristics of an object. Number systems Number system methods of writing numbers

1. What is a number system? A number system is a set of techniques and rules by which numbers are written and read. There are positional and non-positional number systems. In non-positional

Translation of numbers in positional number systems. Any positional system is characterized by its base. The radix of a positional number system is the number of different signs or symbols used

Electronic textbook on computer science Systems Translation of numbers from the binary system Arithmetic operations in positional systems in floating format. Statement of the problem: While studying the subject of computer science at school,

Preparation for the Unified State Exam. Lesson 1 October 1, 2017 27 tasks for 35 points: Part I: 23 short answer tasks (number or word) 23 points Part II: 4 long answer tasks (code or description of the result)

Coding is the representation of characters from one alphabet by characters from another according to certain rules. A number system is a way of representing any number using an alphabet of symbols called digits. Non-positional

16 (advanced level, time min) Topic: Number coding. Number systems. What you need to know: the principles of encoding numbers in positional number systems in order to convert a number, say 15, from the system

Number systems 1. Introduction 2. Binary system 3. Octal system 4. Hexadecimal system K.Yu. Polyakov, 2007-2012 Number systems Topic 1. Introduction K.Yu. Polyakov, 2007-2012 Definitions System

Chapter 3 Information and logical foundations for constructing computers Information and logical foundations for constructing computers cover a range of issues related to forms and representation systems

There are positional and non-positional number systems.

IN non-positional systems, the weight of a digit (i.e., the contribution it makes to the value of a number) does not depend on its position in the notation of the number. Thus, in the Roman number system in the number XXXII (thirty-two), the weight of the number X in any position is simply ten.

IN positional In number systems, the weight of each digit varies depending on its position (position) in the sequence of digits representing the number. For example, in the number 757.7, the first seven means 7 hundreds, the second - 7 units, and the third - 7 tenths of a unit.

The very notation of the number 757.7 means an abbreviated notation of the expression

700 + 50 + 7 + 0,7 = 7 10 2 + 5 10 1 + 7 10 0 + 7 10 -1 = 757,7.

Any positional number system is characterized by its base.

Any natural number can be taken as the base of the system - two, three, four, etc. Consequently, an infinite number of positional systems are possible: binary, ternary, quaternary, etc. Writing numbers in each number system with a base q means a shorthand expression

a n-1 q n-1 + a n-2 q n-2 + ... + a 1 q 1 + a 0 q 0 + a -1 q -1 + ... + a -m q -m ,

Where a i– numbers of the number system; n And m– the number of integer and fractional digits, respectively.

For example:

How are integers generated in positional number systems?

In every number system, digits are ordered according to their meanings: 1 is greater than 0, 2 is greater than 1, etc.

To promote the number 1 means to replace it with 2, to promote the number 2 means to replace it with 3, etc. Advancing the highest digit (for example, the number 9 in the decimal system) means replacing it with 0. In binary system using only two digits - 0 and 1, promoting 0 means replacing it with 1, and promoting 1 means replacing it with 0.

Integers in any number system are generated using the Counting Rule:

Applying this rule, we write down the first ten integers

· in binary system: 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001;

· in the ternary system: 0, 1, 2, 10, 11, 12, 20, 21, 22, 100;

· in the fivefold system: 0, 1, 2, 3, 4, 10, 11, 12, 13, 14;

· octal system: 0, 1, 2, 3, 4, 5, 6, 7, 10, 11.

What number systems do specialists use to communicate with a computer?

In addition to decimal, systems with the base being integer power of 2, namely:

· binary (digits 0, 1 are used);

· octal (digits 0, 1, ..., 7 are used);

hexadecimal (for the first integers from zero to nine, the digits 0, 1, ..., 9 are used, and for the next numbers - from ten to fifteen - the characters A, B, C, D, E, F are used as digits) .

It is useful to remember the notation in these number systems for the first two tens of integers:

10th 2nd 8th 16th
10th 2nd 8th 16th
A
B
C
D
E
F

Of all the number systems, the binary number system is especially simple and therefore interesting for technical implementation in computers.

How to convert an integer from the decimal system to any other positional number system?

Example: Convert the number 75 from decimal to binary, octal and hexadecimal:

Answer: 75 10 = 1 001 011 2 = 113 8 = 4B 16.

Addition

Addition tables are easy to create using the Counting Rule.

Addition in hexadecimal

When adding, the numbers are summed by digits, and if there is an excess, it is transferred to the left.

Example 1. Let's add the numbers 15 and 6 in different number systems.

Example 2. Add the numbers 15, 7 and 3.

Hexadecimal: F 16 +7 16 +3 16 Answer: 5+7+3 = 25 10 = 11001 2 = 31 8 = 19 16. Check: 11001 2 = 2 4 + 2 3 + 2 0 = 16+8+1=25, 31 8 = 3*8 1 + 1*8 0 = 24 + 1 = 25, 19 16 = 1*16 1 + 9 *16 0 = 16+9 = 25.

Example 3. Add the numbers 141.5 and 59.75.

Answer: 141.5 + 59.75 = 201.25 10 = 11001001.01 2 = 311.2 8 = C9.4 16

Examination. Let's convert the resulting amounts to decimal form:
11001001,01 2 = 2 7 + 2 6 + 2 3 + 2 0 + 2 -2 = 201,25
311,2 8 = 3*8 2 + 1 8 1 + 1*8 0 + 2*8 -1 = 201,25
C9.4 16 = 12*16 1 + 9*16 0 + 4*16 -1 = 201.25

Subtraction

Example 4. Subtract one from the numbers 10 2, 10 8 and 10 16

Example 5. Subtract one from the numbers 100 2, 100 8 and 100 16.

Example 6. Subtract the number 59.75 from the number 201.25.

Answer: 201.25 10 – 59.75 10 = 141.5 10 = 10001101.1 2 = 215.4 8 = 8D.8 16.

Examination. Let's convert the resulting differences to decimal form:
10001101,1 2 = 2 7 + 2 3 + 2 2 + 2 0 + 2 –1 = 141,5;
215,4 8 = 2*8 2 + 1*8 1 + 5*8 0 + 4*8 –1 = 141,5;
8D.8 16 = 8*16 1 + D*16 0 + 8*16 –1 = 141.5.

Multiplication

When multiplying multi-digit numbers in different positional number systems, you can use the usual algorithm for multiplying numbers in a column, but the results of multiplying and adding single-digit numbers must be borrowed from the multiplication and addition tables corresponding to the system in question.

Multiplication in binary system Multiplication in octal system

Due to the extreme simplicity of the multiplication table in the binary system, multiplication is reduced only to shifts of the multiplicand and additions.

Example 7. Multiply the numbers 5 and 6.

Answer: 5*6 = 30 10 = 11110 2 = 36 8.


11110 2 = 2 4 + 2 3 + 2 2 + 2 1 = 30;
36 8 = 3 8 1 + 6 8 0 = 30.

Example 8. Multiply the numbers 115 and 51.

Answer: 115*51 = 5865 10 = 1011011101001 2 = 13351 8.

Examination. Let's convert the resulting products to decimal form:
1011011101001 2 = 2 12 + 2 10 + 2 9 + 2 7 + 2 6 + 2 5 + 2 3 + 2 0 = 5865;
13351 8 = 1*8 4 + 3*8 3 + 3*8 2 + 5*8 1 + 1*8 0 = 5865.

Division

Division in any positional number system is carried out according to the same rules as division by angle in the decimal system. In the binary system, division is especially simple, because the next digit of the quotient can only be zero or one.

Example 9. Divide the number 30 by the number 6.

Answer: 30: 6 = 5 10 = 101 2 = 5 8.

Example 10. Divide the number 5865 by the number 115.

Octal: 13351 8:163 8

Answer: 5865: 115 = 51 10 = 110011 2 = 63 8.


110011 2 = 2 5 + 2 4 + 2 1 + 2 0 = 51; 63 8 = 6*8 1 + 3*8 0 = 51.

Example 11. Divide the number 35 by the number 14.

Octal: 43 8: 16 8

Answer: 35: 14 = 2.5 10 = 10.1 2 = 2.4 8.

Examination. Let's convert the resulting quotients to decimal form:
10,1 2 = 2 1 + 2 -1 = 2,5;
2,4 8 = 2*8 0 + 4*8 -1 = 2,5.

Addition and subtraction

When adding the reciprocal codes of numbers A and B, there are four main and two special cases:

1. A and B are positive. When summing, all digits are added, including the sign digit. Since the sign digits of the positive terms are equal to zero, the sign digit of the sum is also zero. For example:

The correct result was obtained.

The correct result was obtained in the reverse code. When converted to direct code, the bits of the digital part of the result are inverted: 1 0000111 = –7 10 .

The computer corrects the initially obtained incorrect result (6 instead of 7) by transferring a unit from the sign digit to the least significant digit of the sum.

The initially obtained incorrect result (reverse code of the number –11 10 instead of the reverse code of the number –10 10) is corrected by the computer by transferring the unit from the sign digit to the low order digit of the sum.

When converting the result into a direct code, the bits of the digital part of the number are inverted: 1 0001010 = –10 10 .

When adding, a situation may arise when the high-order bits of the operation result do not fit in the memory area allocated for it. This situation is called overflow of the number format bit grid. To detect overflows and notify about an error that has occurred, special tools are used in the computer. Below are two possible cases of overflow.

5. A and B are positive, the sum of A+B is greater than or equal to 2 n–1, where n is the number of digits of the number format (for a single-byte format n=8, 2 n–1 = 27 = 128). For example:

The seven digits of the digital part of the number format are not enough to accommodate an eight-digit sum (162 10 = 10100010 2), so the most significant bit of the sum ends up in the sign bit. This causes a mismatch in the sign of the sum and the signs of the terms, which is evidence of overflow of the bit grid.

Here the sign of the sum also does not coincide with the signs of the terms, which indicates an overflow of the bit grid.

All these cases also occur when adding additional codes numbers:

1. A and B are positive. There are no differences here from case 1, considered for the reverse code.

2. A is positive, B is negative and is greater in absolute value than A. For example:

The correct result was obtained in two's complement code. When converting to a direct code, the bits of the digital part of the result are inverted and one is added to the least significant digit: 1 0000110 + 1 = 1 0000111 = –7 10 .

3. A is positive, B is negative and is less in absolute value than A. For example:

The correct result was obtained. The computer discards the carry unit from the sign bit.

4. A and B are negative. For example:

The correct result was obtained in two's complement code. The computer discards the carry unit from the sign bit.

Overflow cases for complementary codes are considered by analogy with cases 5 and 6 for reverse codes.

A comparison of the considered forms of encoding signed integers shows:

· the computer spends less time converting a negative number into a reverse code than converting it into an additional code, since the latter consists of two steps - generating the reverse code and adding one to its least significant digit;

· the addition time for additional codes of numbers is less than for their reverse codes, because in such addition there is no transfer of one from the sign bit to the least significant bit of the result.

Multiplication and division

In many computers, multiplication is performed as a sequence of additions and shifts. To do this, the ALU has a register called an accumulating adder, which contains the number zero before the operation begins. During the operation, the multiplicand and the results of intermediate additions are alternately placed in it, and upon completion of the operation, the final result is placed.

The other ALU register involved in this operation first contains the multiplier. Then, as additions are performed, the number it contains decreases until it reaches zero.

For illustration, let's multiply 110011 2 by 101101 2.

Division is a difficult operation for a computer. It is usually implemented by repeatedly adding an additional divisor code to the dividend.

Addition and subtraction

When adding and subtracting, a preparatory operation called order alignment is first performed.

As a result of order alignment, the same digits of numbers are located in the corresponding digits of both registers, after which the mantissas are added or subtracted.

If necessary, the resulting result is normalized by shifting the mantissa of the result to the left. After each left shift, the order of the result is reduced by one.

Example 1. Add the binary normalized numbers 0.10111 2 –1 and 0.11011*2 10. The difference in the orders of the terms here is three, therefore, before addition, the mantissa of the first number is shifted three digits to the right:

Example 2. Subtract the binary normalized numbers 0.10101*2 10 and 0.11101*2 1. The difference between the orders of the minuend and the subtrahend here is equal to one, therefore, before subtraction, the mantissa of the second number is shifted one digit to the right:

The result was not normalized, so its mantissa is shifted to the left by two digits with a corresponding decrease in order by two units: 0.1101*2 0 .

Multiplication

Example 3. Perform multiplication of binary normalized numbers:

(0.11101*2 101)*(0.1001*2 11) = (0.11101*0.1001)* 2 (101+11) = 0.100000101*2 1000 .

Division

Example 4. Perform division of binary normalized numbers:

0.1111*2 100: 0.101*2 11 = (0.1111: 0.101) * 2 (100–11) = 1.1*2 1 = 0.11 2 10 .

The use of floating point numbers significantly complicates the arithmetic-logical device design.

Exercises

4.1. Using the Counting Rule, write the first 20 integers in decimal, binary, ternary, quintal, and octal number systems.
[ Answer ]

4.2. What integers follow the numbers:

[ Answer ]

4.4. What digit ends in an even binary number? What digit ends in an odd binary number? What digits can an even ternary number end with?
[ Answer ]

4.5. What is the largest decimal number that can be written in three digits:

o a) in the binary system;

o b) in the octal system;

o c) in hexadecimal?

4.6. In what number system does 21 + 24 = 100?

Solution. Let x be the desired base of the number system. Then 100 x = 1 x 2 + 0 x 1 + 0 x 0, 21 x = 2 x 1 + 1 x 0, 24 x = 2 x 1 + 4 x 0. So x 2 = 2x + 2x + 5 or x 2 - 4x - 5 = 0. The positive root of this quadratic equation is x = 5.
Answer. Numbers are written in the quinary number system.

4.7. In which number system is the following true:

o a) 20 + 25 = 100;

o b) 22 + 44 = 110?

4.8. The decimal number 59 is equivalent to the number 214 in some other number system. Find the basis of this system.
[ Answer ]

4.9. Convert the numbers to decimal, and then check the results by doing the reverse conversions:

[ Answer ]

4.10. Convert numbers from decimal to binary, octal, and hexadecimal, and then check the results by performing the reverse conversions:

a) 125 10; b) 229 10; c) 88 10; d) 37.25 10; e) 206.125 10.
[ Answer ]

4.11. Convert numbers from binary to octal and hexadecimal, and then check the results by performing the reverse conversions:

a) 1001111110111.0111 2 ; d) 1011110011100.11 2;
b) 1110101011,1011101 2; e) 10111,1111101111 2;
c) 10111001,101100111 2; f) 1100010101,11001 2.

[ Answer ]

4.12. Convert hexadecimal numbers to binary and octal systems:

a) 2СE 16; b) 9F40 16; c) ABCDE 16; d) 1010.101 16; e) 1ABC,9D 16.
[ Answer ]

4.13. Write down the whole numbers:

o a) from 101101 2 to 110000 2 in the binary system;

o b) from 202 3 to 1000 3 in the ternary system;

o c) from 14 8 to 20 8 in the octal system;

o d) from 28 16 to 30 16 in hexadecimal.

4.14. For decimal numbers 47 and 79, perform a chain of translations from one number system to another:

[ Answer ]

4.15. Make tables for adding single-digit numbers in ternary and quinary number systems.
[ Answer ]

4.16. Make multiplication tables for single-digit numbers in ternary and quinary number systems.
[ Answer ]

4.17. Add the numbers and then check the results by performing the appropriate decimal additions:

[ Answer ]

4.18. In which number systems are the following additions performed? Find the basis of each system:

[ Answer ]

4.19. Find those substitutions of decimal digits instead of letters that make the written results correct (different numbers are replaced by different letters):

[ Answer ]

4.20. Subtract:

[ Answer ]

4.21. Multiply the numbers, and then check the results by performing the appropriate decimal multiplications:

a) 101101 2 and 101 2; e) 37 8 and 4 8;
b) 111101 2 and 11.01 2; f) 16 8 and 7 8;
c) 1011.11 2 and 101.1 2; g) 7.5 8 and 1.6 8;
d) 101 2 and 1111.001 2; h) 6.25 8 and 7.12 8.

[ Answer ]

4.22. Divide 10010110 2 by 1010 2 and check the result by multiplying the divisor by the quotient.
[ Answer ]

4.23. Divide 10011010100 2 by 1100 2 and then do the appropriate decimal and octal division.
[ Answer ]

4.24. Calculate the values ​​of the expressions:

o a) 256 8 + 10110.1 2 * (60 8 + 12 10) - 1F 16;

o b) 1AD 16 - 100101100 2: 1010 2 + 217 8 ;

o c) 1010 10 + (106 16 - 11011101 2) 12 8 ;

o d) 1011 2 * 1100 2: 14 8 + (100000 2 - 40 8).

4.25. Arrange the following numbers in ascending order:

o a) 74 8, 110010 2, 70 10, 38 16;

o b) 6E 16, 142 8, 1101001 2, 100 10;

o c) 777 8, 101111111 2, 2FF 16, 500 10;

o d) 100 10, 1100000 2, 60 16, 141 8.

4.26. Write down the decreasing series of numbers +3, +2, ..., -3 in one-byte format:

o a) in direct code;

o b) in reverse code;

o c) in additional code.

4.27. Write the numbers in direct code (1 byte format):

a) 31; b) -63; c) 65; d) -128.
[ Answer ]

4.28. Write the numbers in reciprocal and complement codes (1 byte format):

a) -9; b) -15; c) -127; d) -128.
[ Answer ]

4.29. Find decimal representations of numbers written in two's complement code:

a) 1 1111000; b) 1 0011011; c) 1 1101001; d) 1 0000000.
[ Answer ]

4.30. Find decimal representations of numbers written in reverse code:

a) 1 1101000; b) 1 0011111; c) 1 0101011; d) 1 0000000.
[ Answer ]

4.31. Perform subtraction of numbers by adding their reciprocal (complementary) codes in 1 byte format. Indicate in what cases the bit grid overflow occurs:

a) 9 - 2; d) -20 - 10; g) -120 - 15;
b) 2 - 9; e) 50 - 25; h) -126 - 1;
c) -5 - 7; f) 127 - 1; i) -127 - 1.

[ Answer ]

Lecture 4. Arithmetic foundations of computers

The processor performs arithmetic and logical operations on binary codes. Therefore, to get an idea of ​​​​the structure of a computer, it is necessary to become familiar with the basic logical elements that underlie its construction. To understand the operating principle of such elements, we will begin this acquaintance with the basic initial concepts of logical algebra.

Logic is the science of forms and methods of thinking. This is the study of methods of reasoning and evidence. A concept is a form of thinking that identifies the essential features of an object or class of objects, allowing them to be distinguished from others. Example Rectangle, pouring rain, computer - these are concepts.

A statement is a formulation of your understanding of the world around you. A statement is a declarative sentence in which something is affirmed or denied. A statement in which the connection of concepts correctly reflects the properties and relationships of real things will be true. A statement will be false if it contradicts reality.

Example “The letter “a” is a vowel” is a true statement. “The computer was invented in the mid-19th century” is a false statement.

Exercise. Which of the sentences are statements? Determine their truth. 1. How long is this tape? (not a statement) 2. Do morning exercises! (not a statement) 3. Paris is the capital of England. (is a false statement) 4. The number 11 is prime. (is a true statement) 5. 4 + 5 = 10 (is a false statement) 6. You can’t pull a fish out of a pond without difficulty. (is a true statement) 7. Some bears live in the north. (is a true statement) 8. All bears are brown. (is a false statement)

Inference is a form of thinking with the help of which a new judgment (knowledge or conclusion) can be obtained from one or more judgments. Example Given the statement: “All angles of an isosceles triangle are equal.” Obtain the statement “This triangle is equilateral” by inference.

LOGICAL EXPRESSIONS AND OPERATIONS Logic algebra is the science of general operations, similar to addition and multiplication, that are performed on statements.

A Boolean variable is a simple statement containing only one thought. Its symbolic designation is a Latin letter (for example, A, B, X, Y, etc.) A compound statement is a logical function that contains several simple thoughts connected to each other using logical operations. Its symbolic designation is F(A, B, …). Compound statements can be constructed from simple statements.

Logical operations - logical action. A truth table is a table that determines the meaning of a complex statement for all possible meanings of simple statements. Let's consider three basic logical operations - conjunction, disjunction and negation and additional ones - implication and equivalence.

If a compound statement (logical function) is expressed in the form of a formula that includes logical variables and signs of logical operations, then you get a logical expression whose value can be calculated. The value of a Boolean expression can only be FALSE or TRUE. When composing a logical expression, it is necessary to take into account the order in which logical operations are performed, namely: actions in brackets; inversion, conjunction, disjunction, implication, equivalence.

Example Write down the following statement as a logical expression: “In the summer Petya will go to the village and, if the weather is good, he will go fishing.” Let's analyze the compound statement. It consists of the following simple statements: “Petya will go to the village,” “The weather will be good,” “He will go fishing.” Let's denote them through logical variables: A = Petya will go to the village; B = The weather will be good; C = He will go fishing. Let's write the statement in the form of a logical expression, taking into account the order of actions. If necessary, place parentheses: F = A & (B → C).



Related publications