Menu
Is free
registration
home  /  Navigators/ Any number can be considered as real. Representing numbers in a computer

Any number can be considered as real. Representing numbers in a computer

main feature balanced number systems - when performing arithmetic operations, the "sign rule" is not used.

Using the Fibonacci number system. At the dawn of the computer era, two more discoveries were made in the field of positional ways of representing numbers, which, however, are little known and did not attract much attention of mathematicians and engineers at that time. We are talking about the properties of the Fibonacci number system, or the SS of the golden ratio.

In the last decades of the XX century, a group of mathematicians led by a professor in the USSR obtained extremely interesting results related to solving the problem of the reliability of storage, processing and transmission of information in computer systems... Mathematicians proposed to use the Fibonacci system as a SS in computers. Recall that the alphabet of this system is the numbers 0 and 1, and the basis is the sequence of Fibonacci numbers: 1, 2, 3, 5, 8, 13, 21,

The main advantage of Fibonacci codes for practical applications consists in their "natural" redundancy, which can be used for the purpose of controlling numeric conversions. This redundancy manifests itself in the property of multiple representations of the same number. For example, the number 30 in the Fibonacci code has several representations:

30 = 1001101fib = 1010001fib = 111101fib.

In this case, different code representations of the same number can be obtained from each other using special Fibonacci convolution (011 → 100) and sweep (100 → 011) operations performed on the code image of the number. If we perform all possible convolutions over the code image, then we come to a special Fibonacci image, called minimal form , in which there are no two adjacent units. If we perform all possible sweep operations in the code image, then we come to a special Fibonacci image, called maximum , or deployed ,form , in which two zeros do not occur next to each other.

The analysis of Fibonacci arithmetic showed that its main operations are the operations of convolution, unfolding and the operation based on them of reducing the Fibonacci code to the minimum form.

These mathematical results became the basis for the project of creating computer and measuring systems based on the Fibonacci number system.

When developing the element base of new computer technology, the main operational element was the device for reducing the Fibonacci code to a minimum form. This device was implemented through RS-flip-flops and gates "AND" and "OR". Were created prototypes of a microcircuit that performs the following operations: writing and reading data, convolution, sweeping, moving, absorbing, reducing to the minimum form, summing, subtracting, reversing shift, logical multiplication, logical addition and addition modulo 2.

A distinctive feature of the microcircuit was the presence of a control output, on which information about wrong work microcircuits.

Thus, the main result of this development was the creation of the first ever computer technology microcircuits for the implementation of a self-monitoring Fibonacci processor with a 100% guarantee of detecting failures that occur when switching triggers.

And although it has not yet been possible to create a Fibonacci computer for various reasons, theoretical basis of this direction are of undoubted interest and can become a source of new ideas not only in the computer field, but also in the field of mathematics. The use of "Fibonacci" representations in measuring technique and digital processing signals.

Use of a residual class system. In the development of computer technology, mathematicians are always faced with the most difficult problem - the creation of efficient (they are often called "limiting") algorithms for performing arithmetic operations in a computer. As part of solving this problem, scientists invented new number systems and developed computer arithmetic based on them, which make it possible to build computing devices, the speed and reliability of which are superior to computers based on binary arithmetic. These SS include a non-positional system of residual classes, some hierarchical number systems, etc.

Hierarchical number systems are constructed on the basis of the idea of ​​combining positional and non-positional SS, while they must combine positive sides systems included in them and be free from their shortcomings. The principle of constructing hierarchical SS is generally simple. Some external system reckoning A with alphabet a... The numbers of this system are written in the form of words (codes) of another (internal) number system V with alphabet R... An example of such a SS is the well-known binary-decimal system used to represent decimal numbers in some computers.

The residual class system (RNS) is a non-positional SS, the numbers in which are represented by the remainder of the division by the chosen base system P 1, P 2, ..., Rn and are coprime numbers. The operations of addition, subtraction and multiplication on numbers in the RNS are performed independently for each base, without carrying over between digits.

Operations such as division, comparison, etc., requiring information about the value of the entire number, are performed in the RNS according to more complex algorithms. This is a significant drawback of this number system, which hinders its widespread use as a computer. However, today in modern computers when working with large and super-large numbers, RNS are used, because only RNS arithmetic allows you to get the results of calculations in real time.

In such cases, values ​​close to 2 m (m- the binary capacity of the computer), for example: 2 m-1 – 1, 2m, 2m-1 + 1, etc. Since the middle of the last century, scientists from many countries of the world have been dealing with the problem of increasing the speed of "inconvenient" operations in the RNS. The RNS itself has been widely used in computing systems for several decades.

4.5. Forms of presentation and transformation of information

4.5.1. Encoding and decoding information

In any kind of work with information, we are always talking about its representation in the form of certain symbolic structures.

The most common one-dimensional representations of information, in which messages are in the form of a sequence of characters. However, its multidimensional representation is also widely used.

Information is presented in various forms during the perception of the environment by living organisms and humans, in the processes of information exchange between humans and humans, humans and computers, computers and computers, etc. Conversion of information from one form of representation (sign system) to another is called coding .

In a narrow sense, coding is understood as a transition from the initial representation of information, convenient for human perception, to a representation that is convenient for storage, transmission and processing.

Going back to the original view is called decoding .

The coding means is a table of correspondence of sign systems, which establishes a one-to-one correspondence between signs or groups of signs of two different sign systems.

In the process of exchanging information, it is often necessary to perform operations of encoding and decoding information. When you enter an alphabet character into a computer by pressing the corresponding key on the keyboard, the character is encoded, that is, it is converted into a computer code. When a character is displayed on the screen of a monitor or printer, the reverse process occurs - decoding, when the character is converted from a computer code into its graphic image.

Let us consider, as an example of coding, the correspondence of the digital and bar codes of a product. Such codes are available on each product and allow you to fully identify the product (country and company of the manufacturer, type of product, etc.).

The digital code characters (numbers) correspond to the group of bar code characters (narrow and wide strokes, as well as the size of the spaces between them). For a person, a digital code is convenient, and for automated accounting - a bar code, which is read using a narrow light beam and is further processed in computer accounting systems.

When coding information, the following goals are set:

· Convenience of physical implementation;

· Ease of perception;

· High speed of transmission and processing;

· Efficiency, that is, reducing the redundancy of the message;

· Reliability, that is, protection against accidental distortion;

Safety, i.e. protection against unwanted access to information.

These goals often contradict each other, for example, economy requires reducing the redundancy of the message, and reliability is achieved only due to this very redundancy.

For manipulating the information presented in the computer, the storage device (or memory) of the computer is intended.

Information in the computer memory is recorded in the form of a digital binary code. In a computer, binary coding is used to represent information, since it was possible to create reliably working technical devices, which can save and recognize no more than two different states (numbers) with one hundred percent reliability:

· Electromagnetic relays (closed / open); were widely used in the designs of the first computers;

· Area of ​​the surface of the magnetic information carrier (magnetized / demagnetized);

· Area of ​​the surface of the laser disk (reflects / does not reflect);

Trigger; can be stably in one of two states; widely used in random access memory computer.

All types of information in a computer are encoded in machine language in the form of logical sequences of zeros and ones (Fig. 4.2).

Type of information

Binary code

Numeric

Text

Graphic

Sound

Rice. 4.2. Binary encoding information

Information in a computer is represented in binary code, the alphabet of which consists of two numbers (0 and 1).

Binary code numbers can be viewed as two equally probable states (events). When writing a binary digit, the choice of one of two possible states (one of two digits) is realized, and, therefore, it carries an amount of information equal to 1 bit.

The amount of information that can fit in one element (0 or 1), called bit , very little and does not carry any semantic meaning. However, if you connect several such elements into a cell, then you can store in the memory as much information as you need.

It is important that each digit of the machine binary code carries information in 1 bit. Thus, two digits carry information in 2 bits, three digits - in 3 bits, etc. The amount of information in bits is equal to the number of digits of the binary machine code.

A sequence of bits, considered by the hardware of the computer as a whole, is called machine word .

4.5.2. Units for measuring the amount of information

A unit of information amount is taken to be such an amount of information that contains a message that halves the uncertainty. Unit of measurement of the amount of information bit (bit) gets its name from the English phrase Binary digit Is a binary digit.

If we return to the experiment with tossing a coin, then here the uncertainty is just halved and, therefore, the amount of information received is equal to 1 bit.

1 byte = 23 bits = 8 bits.

In computer science, the education system of multiple units for measuring the amount of information is somewhat different from those adopted in most sciences. Traditional metric systems, such as the International System of Units (SI), use a factor of 10 as multiples of multiples. n, where n= 3, 6, 9, etc., which corresponds to the decimal prefixes Kilo (103), Mega (106), Giga (109), etc.

The computer operates with numbers not in decimal, but in binary system reckoning, therefore, in multiple units of measuring the amount of information, the coefficient 2 is used n.

So, multiple byte units of measurement of the amount of information are entered as follows:

1 KB = 210 bytes = 1024 bytes;

1 MB = 210 KB = 1024 KB;

1 GB = 210 MB = 1024 MB.

4.5.3. Signed and unsigned integer representation

Any integer can be considered as a real number, but with a zero fractional part, that is, one could limit ourselves to the representation of real numbers in a computer and the implementation of arithmetic operations on them. However, for effective use memory, increasing the speed of performing calculations and introducing the operation of division entirely with a remainder, integers are represented in specially designed ways.

The introduction of special ways of representing integers is justified by the fact that quite often in problems solved with the help of a computer, many actions are reduced to operations on integers. For example, in problems of an economic nature, data is the number of shares, employees, parts, vehicles, etc., which are integers in their meaning. Integers are used both to indicate the date and time, and to number various objects: array elements, database records, machine addresses, etc.

For the computer representation of integers, several different representations are usually used, differing from each other in the number of digits and the presence or absence of a sign digit. Unsigned representation can only be used for
non-negative integers, negative numbers are represented only in signed form.

With unsigned representation, all bits of the cell are assigned to the number itself. When represented with a sign, the most senior (left) digit is assigned to the sign of the number, the remaining digits are assigned to the actual number. If the number is positive, then 0 is placed in the signed bit, if the number is negative - 1. Obviously, cells of the same size can represent a larger range of non-negative integers in unsigned representation than signed numbers. For example, in one byte (8 bits) you can write positive numbers from 0 to 255,
and with a sign - only up to 127. Therefore, if it is known in advance that some numerical value is always non-negative, then it is more advantageous to consider it as unsigned.

They say that integers in a computer are stored in the format with fixed point.

Representation of positive integers . To get the computer representation of an unsigned integer in k-bit memory cell, it is enough to translate it into the binary number system and supplement the result obtained with zeros on the left to k discharges. It is clear that there is a limit on the numbers that we can write in k-bit cell.

The maximum representable number corresponds to ones in all digits of the cell (a binary number consisting of k units). For
k-bit representation it will be equal to 2 k- 1. The minimum number is represented by zeros in all digits of the cell, it is always equal to zero. Following are the maximum numbers for unsigned representation when different meanings k:

Number of discharges

Maximum number

With the signed representation of integers, concepts such as forward, backward and complementary codes arise.

Representation of a number in the familiar form of "sign-value", in which the most significant digit of the cell is assigned to the sign, the rest k - 1 digits - under the digits of the number, called direct code .

For example, the direct codes of binary numbers 110012 and –110012 for an eight-bit cell are equal and respectively. Positive integers are represented in a computer using a straightforward code. The forward code of a negative integer differs from the forward code of the corresponding positive number in the contents of the sign bit. But instead of direct code, a computer uses complementary code to represent negative integers.

Note that the maximum positive number that can be written in signed representation in k digits is equal to 2 k–1–1, which is almost two times less than the maximum number in the unsigned representation in the same k discharges.

Example

Determine the maximum positive number in signed eight and sixteen digit representations of numbers.

Solution... The maximum positive number in 8 bits is 127 (27 - 1), in 16 bits it is 32 - 1).

Example

Number 53 = 1101012 in eight-bit representation is.

The same number 53 in 16 digits will be written as follows:.

In either case, it doesn't matter if the signed or unsigned representation is used.

Example

For 200 =, a signed 8-bit representation is not possible, since the maximum allowed number in such a representation is 127, but in an unsigned eight-bit representation it looks like.

Back ,additional number codes . To represent negative integers in a computer, an additional code is used, which allows you to replace the arithmetic operation of subtraction with an addition operation, which significantly increases the speed of calculations. Before introducing the definition of additional code, we make the following important note.

V k-bit integer computer arithmetic 2 k ≡ 0.

This can be explained by the fact that the binary notation of the number 2 k consists of one unit and k zeros, and into a cell from k digits can only fit k digits, in this case only k zeros. In this case, they say that the significant unit has gone beyond the bit grid.

k-bit additional code negative number T Is an entry in k digits of positive number 2 k– |t | where | t |- modulus of negative number T,| t |< 2k– 1.

Let's figure out what and to what additional code complements. Negative number's complement code T Is the addition of the modulus of this number to 2 (or to zero in k-bit arithmetic):

(2k– |T|) + |T| = 2k ≡ 0.

Algorithm for obtaining additional k-bit code of a negative number:

1. The module of a number is represented by direct code in k binary digits.

2. Invert the values ​​of all digits (replace all zeros with ones, and ones with zeros), thus obtaining k-bit reverse code original negative number.

3. To the resulting reverse code, interpreted as k-bit non-negative binary number, add one.

The inverse code is the complement of the original number to the number
2k– 1 consisting of k binary ones. Therefore, adding one to the inverted code allows you to get its required complementary code.

Example

We get the additional code of the number -52 for eight - and sixteen-digit cells. For an eight-bit cell:

0011 0100 - direct code of the number | –52 | = 52;

1100 1011 - reverse code of the number -52;

1100 1100 is the additional code of the number -52. For a sixteen-bit cell: 0000 0000 0– direct number code | –52 |;
1111 1111 1100 1011 - reverse code of the number -52; 1111 1111 1100 1100 - additional code of the number -52.

4.5.4. Representation of symbolic information in a computer

Symbolic information is stored and processed in the computer memory in the form of a digital code. Since binary codes are used on automatic information processing devices, the digital codes corresponding to the symbols are translated into a binary system.

When converting characters (signs) into a digital code, a one-to-one correspondence must take place between the sets of characters and codes.

The character encoding table for 8-bit numbers, introduced by the US Institute for Standardization and became the de facto international standard, is called ASCII (American Standard Code for Information Interchange).

The basic part of the ASCII table fixes the values ​​of codes from 0 to 127 and is generally accepted throughout the world, and the extended part refers to characters with numbers from 128 to 255.

The first 32 codes of the base table, starting from zero, contain control codes that do not correspond to any language characters, and, accordingly, these codes are not displayed on the screen and printing devices. Codes 32 through 127 correspond to the English alphabet, punctuation marks, arithmetic operations, and some auxiliary characters.

Each country uses its own extended part of the ASCII table (codes 128-255, or extended ASCII codes), which contains the letters of the national alphabets, pseudo-graphic symbols and scientific symbols. In Russia, for the extended part of the table, the encodings KOI-8, Windows-1251, ISO, etc. are used. Therefore, texts created in one encoding will not be displayed correctly in another encoding.

Difficulties in creating unified system data encoding for the whole world are caused by a limited set of codes. Obviously, if you encode characters not with eight-bit binary numbers, but with numbers with big amount digits, then the range of possible values ​​of the codes will become much larger. This system, based on 16-bit character coding, is called universal - UNICODE. Sixteen digits make it possible to provide unique codes for 216 = 65536 different characters - this is enough to accommodate most of the world's languages ​​in one character table.

4.5.5. Floating point representation

Unlike ordinal types (all integers, symbolic, logical), the values ​​of which are always compared with a number of integers and, therefore, are represented in the memory of the machine absolutely exactly, the value of real types determines the number only with some finite precision, depending on the internal format of the real number ...

Writing a floating point number is very effective remedy representations of very large and very small real numbers, provided that they contain a limited number of significant digits, and, therefore, not all real numbers can be represented in memory. Typically, the number of significant digits used in calculations is such that round-off errors are negligible for most problems.

Any real number x, represented in radix N, can be written as

x = ± mN ± p,

where m- mantissa; p- number order.

If | m| < 1, то запись числа называется нормализованной слева.

The following examples show how any number can be represented in floating point form:

a) in decimal notation

372.95 = 0.37295 103;

25 = 0.025 · 103 = 0.25 · 102;

0.0000015 = 0.15 · 10–5 = 0.015 · 10–4;

b) in the binary number system

11010.1101 = 0.26 = 0.25;

0.011011 = 0.11011 2-1;

0.1 = 0.1 20.

Here the order determines how many positions and in which direction the comma in the mantissa should be shifted.

The number is called normalized to the right if there is a nonzero after the comma in the mantissa. For example, the numbers 0.0007610 and 0, presented respectively in the form 0.076 · 10-2 and 0.011 · 2-2 are not normalized on the right, but in the form 0.76 · 10-3 and 0.11 · 2-3 are such.

Currently distributed (described in IEEE standard 754) also another form of notation - normalized, in which the mantissa of a decimal number takes values ​​from 1 (inclusive) to 10
(not inclusive), and the mantissa of a binary number takes values ​​from 1 (inclusive) to 2 (not inclusive) (1 ≤ mN). In this form, any number (except 0) is written uniquely. The disadvantage is that it is impossible to represent 0 in this form, therefore, the representation of numbers in computer science provides a special sign (bit) for the number 0.

Since the most significant bit (integer part of the number) of the mantissa of a binary number (except 0) in normalized form is equal to "1", then when writing the mantissa of a number in a computer, the most significant bit can be omitted, which is used to reduce the amount of stored information or (at the same volume) to increase the accuracy of storing the number.

0 "style =" border-collapse: collapse; border: none ">

Significant digits

Characteristic

on the characteristic

X = 27 + p - 1

X = 210 + p - 1

X = 214 + p - 1

The algorithm for forming the machine representation of a real number in the computer memory consists of the following points:

1. The number is represented in binary code.

2. The binary number is normalized. In this case, for numbers larger than one, the floating point is carried to the left, defining a positive order. For numbers less than one, the point wraps to the right, defining a negative order.

3. Taking into account the type of the real number, the characteristic is determined according to the table.

4. In the field allotted in memory, in accordance with the type of number, the mantissa, characteristic and sign of the number are written. In doing so, the following should be noted:

· For numbers of type real, the characteristic is stored in the low byte of memory, for numbers of type single, double, extended - in high bytes;

· The sign of the number is always in the most significant bit of the most significant byte;

· The mantissa is always stored in direct code;

· The first bit of the mantissa (always 1 for a normalized number) for numbers like real, single, double is not stored (it is hidden). In extended numbers, all the digits of the mantissa are stored in the computer memory.

The format of the machine data representation (for example, the single type) is as follows:

ml. byte st. byte

6– No. of memory bits

m....m m....m NS m...m s NS...NS

where s- sign bit;

NS- characteristic of the number;

m Is the normalized mantissa.

Keywords:

  • discharge
  • unsigned integer representation
  • signed integer representation
  • representation of real numbers
  • floating point format

1.2.1. Integer representation

Computer memory consists of cells, each of which is physical system consisting of a number of homogeneous elements. These elements have two stable states, one of which corresponds to zero, and the other to one. Each such element is used to store one of the bits - the digits of a binary number. That is why each cell element is called a bit or discharge (Fig. 1.2).

Rice. 1.2. Memory cell

For the computer representation of integers, several different representations are used, differing from each other in the number of bits (8, 16, 32 or 64 bits are usually allocated for integers) and the presence or absence of a sign digit. Unsigned representation can only be used for non-negative integers, negative numbers are represented only in signed form.

Unsigned data has become widespread in computing. These include objects such as cell addresses, all kinds of counters (for example, the number of characters in the text), as well as numbers indicating the date and time, sizes graphic images in pixels, etc.

The maximum value of a non-negative integer number is reached when units are stored in all digits of the cell. For n-bit representation, it will be equal to 2 n -1. The minimum number corresponds to n zeros stored in n memory bits, and is equal to zero.

The following are the maximum values ​​for unsigned n-bit integers:

To obtain a computer representation of an unsigned integer, it is enough to convert the number to the binary number system and supplement the result with zeros on the left to the standard bit width.

Example 1. Number 53 10 = 110101 2 in eight-digit representation is:

The same number 53 in sixteen digits will be written as follows:

When represented with a sign, the most senior (left) digit is assigned to the sign of the number, the remaining digits are assigned to the number itself. If the number is positive, then O is placed in the sign bit, if the number is negative - 1. This representation of numbers is called direct code. In a computer, direct codes are used to store positive numbers in memory devices to perform operations on positive numbers.

The website of the Federal Center for Information and Educational Resources (http://fcior.edu.ru/) contains the information module “Number and its computer code”. With this resource you can get Additional information on the topic under study.

To perform operations with negative numbers, an additional code is used to replace the operation of subtraction by addition. You can find out the algorithm for generating additional code using the information module “Additional code” posted on the website of the Federal Center for Information and Educational Resources (http://fcior.edu.ru/).

1.2.2. Representation of real numbers

Any real number A can be written in normal (scientific, exponential) form:

А = ± m q p,

    m is the mantissa of the number;

    p is the order of the number.

For example, the number 472,000,000 can be represented as follows: 47.2 10 7, 472 10 6, 4720 10 7, etc.

You might have come across the normal form of writing numbers when performing calculations using a calculator, when the answer was received records of the following form: 4.72E + 8.

Here, the "E" sign denotes the base of the decimal number system and reads as "multiply by ten to the power."

From the above example, you can see that the position of the comma in the number record can change. Therefore, the representation in a computer of real numbers in normal form is called floating point representation.

For consistency, the mantissa is usually written as a regular fraction with a nonzero digit after the decimal point. In this case, the number 472,000,000 will be represented as 0.472 10 9

A floating point number can occupy 32 or 64 bits in computer memory. In this case, the digits are allocated for storing the sign of the mantissa, the sign of order, order and mantissa.

The range of representation of real numbers is determined by the number of bits allocated for storing the order of the number, and the precision is determined by the number of bits allocated for storing the mantissa.

The maximum value of the order of number, as you can see from the above example, is 1111111 2 = 127 10, and therefore the maximum value of the number is:

0,11111111111111111111111 10 1111111

Try to figure out for yourself what the decimal equivalent of this value is.

A wide range of floating point numbers is important for solving scientific and engineering problems. At the same time, it should be understood that algorithms for processing numbers in floating point format are more time consuming than algorithms for processing integers.

The most important thing

For the computer representation of integers, several different methods are used, differing from each other in the number of digits (8, 16, 32 or 64) and the presence or absence of a sign digit.

To represent an unsigned integer, it should be converted to a binary number system and padded with zeros from the left to the standard bit width.

When represented with a sign, the most significant bit is assigned to the sign of the number, the remaining digits are assigned to the number itself. If the number is positive, then 0 is placed in the sign bit, if the number is negative, then 1. Positive numbers are stored in the computer in direct code, negative - in complementary.

Real numbers in the computer are stored in floating point format. In this case, any number is written as follows:

А = ± m q p,

    m is the mantissa of the number;

    q - base of the number system;

    p is the order of the number.

Questions and tasks

  1. How are positive and negative integers represented in computer memory?
  2. Any integer can be considered as a real number, but with a zero fractional part. Justify the advisability of having special methods of computer representation of integers.
  3. Represent the number 63 10 in unsigned 8-bit format.
  4. Find the decimal equivalents of numbers by their direct codes, written in signed 8-bit format:
  5. Which of the numbers 443 8, 101010 2, 256 10 can be saved in 8-bit format?
  6. Write down the following numbers in natural form:

      a) 0.3800456 10 2;

      b) 0.245 10 -3;

      c) 1.256900E + 5;

      d) 9.569120E-3.

  7. Write down the number 2010.0102 10 five different ways in normal form.
  8. Write the following numbers in normal form with the normalized mantissa - a regular fraction with a nonzero digit after the decimal point:

    a) 217.934 10;

    c) 0.00101 10.

  9. Draw a diagram linking the key concepts discussed in this paragraph.

§ 1.2. Representing numbers in a computer

Representation of numbers in the computer. Questions and tasks

1. Read the presentation materials for the paragraph contained in electronic application to the textbook. Use these resources to help you answer questions and complete assignments.

2. How are positive and negative integers represented in computer memory?

3. Any integer number can be considered as real, but with zero fractional part. Justify the advisability of having special methods of computer representation of integers.

4. Represent the number 63 10 in unsigned 8-bit format.

5. Find the decimal equivalents of numbers by their direct codes, written in signed 8-bit format:

    a) 01001100;
    b) 00010101.

6. Which numbers 443 8, 101010 2, 256 10 can be saved in 8-bit format?

7. Write down the following numbers in natural form:

    a) 0.3800456 10 2;
    b) 0.245 10 -3;
    a) 1.256900E + 5;
    a) 9.569120E-3.

8. Write down the number 2010.0102 10 in five different ways in exponential notation.

9. Write down the following numbers in exponential form with the normalized mantissa - a regular fraction with a nonzero digit after the decimal point:

    a) 217.934 10;
    b) 75321 10;
    c) 0.00101 10.

10. Draw a diagram linking the key concepts discussed in this paragraph.

Answers: Representing numbers in a computer

    9.a) 0.217934 10 3; b) 0.75321 10 5; c) 0.101 10 -2.

There are two main formats for representing numbers in computer memory, one of them is used to encode integers (representing a number in fixed-point format), the second is used to specify a subset of real numbers (representing a number in floating-point format). Let's consider each of the formats in more detail.

1.1. Integer representation

Any integer can be considered as a real number, but with a zero fractional part, that is, it could be limited to the representation of real numbers in a computer and the implementation of arithmetic operations on them, however, to efficiently use the computer memory, increase the speed of computations and introduce an integer division operation integers are represented in specially designed ways.

For the computer representation of integers, several different methods are usually used, differing from each other in the number of binary digits and the presence or absence of a sign bit.

Integers in a computer are stored in memory in a format with fixed point... In this case, each bit of the memory cell always corresponds to the same bit, and the "comma" "is" on the right after the least significant bit, that is, outside the bit grid.

1.1.1. Unsigned integers

Consider encoding unsigned integers using the example of data of type byte in language Basic and unsigned char in language WITH++ occupying one byte in memory.

To obtain a computer (internal) representation of a one-byte integer non-negative number, it is enough to translate it into a binary number system and the resulting result, called the direct code of the number, is supplemented with zeros on the left to eight bits.

The minimum number is represented by zeros in all digits and is equal to zero. The maximum representable number corresponds to ones in all digits of the cell (a binary number consisting of eight ones), it is equal to 255 (). Examples of encoding single-byte unsigned integers are shown in Table. 1.

One-byte non-negative integers can be used, for example, to organize various counters, record cell addresses, date and time, and size of graphic images in pixels.

To improve the readability of the internal representation of a number, it is written in a hexadecimal number system.

Table 1

Examples of encoding unsigned integers

1.1.2. Signed integers

Consider encoding signed integers using the data type as an example integer in language Basic and int in language WITH++, occupying two bytes (16 bits) in memory.

Each of the 16 bits has a specific purpose, the form of representing a signed integer is shown in Fig. 1. The most significant bit of the cell is assigned under the sign: 0 - for positive numbers, 1 - for negative ones.

To represent signed integers in a computer, an additional code is used, which allows you to replace the arithmetic operation of subtraction with an addition operation, which significantly increases the speed of calculations.

In order to understand what complementary code is, consider forward and reverse codes.

Remark 1... For positive numbers, all three codes match the binary representation of the number using sixteen binary digits, with zeros written to the empty digits.

Rice. 1. Signed integer form

Imagine algorithm obtaining an additional sixteen-bit binary code of a negative number.

1) Write down the direct code of a negative number in 16 binary digits. To do this, the modulus of a negative integer must be converted to a binary number system and the result obtained on the left must be supplemented with zeros to 16 bits.

2) Write the reverse code of a negative number in 16 binary digits. To do this, invert the values ​​of all digits of the direct code (replace all zeros with ones, and all ones with zeros).

3) Write down the complement code of a negative number in 16 binary digits. To do this, add one to the reverse code, considered as a sixteen-bit non-negative binary number.

Remark 2... The inverse code of a negative number is the modulus of this number's complement to the number
, and the complementary code is up to the number
.

Examples of representation of two-byte signed integers are shown in table. 2.

The smallest negative number that can be represented with two bytes is –32768.

The maximum representable positive number corresponds to ones in all digits of the cell (a binary number consisting of zero (in the sign bit) and fifteen ones), it is equal to 32767 (
).

table 2

Examples of representing two-byte signed integers


REPRESENTATION OF INTEGER NUMBERS Since any integer number can be represented as a real number, but with a zero fractional part, it would be possible to limit ourselves to the representation of real numbers in a computer and the implementation of arithmetic operations on them. However, for efficient use of memory, increasing the speed of performing calculations, introducing an integer division operation with a remainder (in pascal DIV and MOD) Integers are represented in specially designed ways.


The introduction of special ways of representing integers is justified by the fact that often in problems solved with a computer, many actions are reduced to operations on integers. For example, in problems of an economic nature, where the data is the number of shares, employees, parts, vehicles, etc. to indicate the date and time; for numbering various objects: array elements, database records, machine addresses, etc.




UNSIGNED INTEGRAL REPRESENTATION All cell digits are assigned to the number itself bit grid digits Example: = Range of represented numbers: A min = = 0 10 A max = = 2 8 -1 = Range In pascal - type BYTE


2.16-bit grid digits Range of represented numbers: A min = = 0 10 A max = = = Range In pascal - type WORD bit grid A min = 0 A max = = bit grid A min = 0 A max = =


INTEGRAL NUMBER PRESENTATION WITH SIGN The most significant digit of the digit grid is assigned to the sign: 0 - for positive number 1 - for negative numbers 1. 8-digit grid digits Example: = Sign of a positive number Example: = Sign of a negative number


The range of represented numbers: A max = = 2 7 -1 = A min = In pascal - type SHORTINT bit grid A max = = = A min = In pascal - type INTEGER




Direct machine code Representation of a number in the usual "sign-value" form, when the first bit of an n-bit word is signed, and the remaining n-1 bits represent the digital digits of a number in the binary number system, is called the direct code of a binary number. The direct code of an integer completely coincides with the recording of the number itself in the bit grid of a computer. The direct code of an integer completely coincides with the recording of the number itself in the bit grid of a computer. The forward code of a negative integer differs from the forward code of the corresponding positive number in the contents of the sign digit. Example. The direct code of the numbers X = and Y = in an eight-bit grid looks like:


In the system of direct codes, there are two different representations of zero: - positive 0; - negative 0. Both representations are completely equal. Direct code is used to store positive and negative numbers in memory devices and to represent positive numbers when performing operations in arithmetic devices.


Supplementary Inverse Codes Complementary and Inverse Codes To simplify the designs of the arithmetic devices of computers, all arithmetic operations, as a rule, are reduced to addition (subtraction operation) or to a series of additions and shifts (multiplication and division). Replacing the operation of subtraction (algebraic addition) with arithmetic addition in a computer is carried out using inverse and complementary codes. Positive's complement code The positive number's complement code is the same as this number.


Explanation of the essence of special codes ... ... - + Let's consider an example of a reverse counter for 3-digit decimal numbers: 999 + 1 = 1000 - overflow of the bit grid! = -according to the counter 999 - code -1! 000 a + (-a) = (-005) = = - additional code of the number - 2 = 5 + (-2) = = - 5 = 7 + (-5) = = If we consider that the overflow unit is lost, then we get correct results To eliminate ambiguity in the ring, we will consider half of the states (0-499) as codes of zero and positive numbers, and the remaining half () as codes of negative numbers.


Complementary code for a negative number The complement code for a negative number is equal to the complement of its value to the number that occurs when the bit grid overflows q n, where q is the base of the number system, n is the number of bits in the bit grid. qn - is called a constant for the formation of an additional code Operation C = A - B, where A and B are positive integers in any number system, can be represented as: C = A - B = A + (-B) = A + (-B ) + qn - qn = A + (qn - B) - qn А - the first term complementary code qn - В - additional code of the number –В (second term) qn - constant eliminating the overflow unit


Example. A = 95 10, B = 43 10, n = 2. Find C = AB. [-B dk] = 100 - 43 = 57 C = 95 + [-B dk] - 100 = - 100 = 152 - 100 = 52 The unit in the most significant digit of the sum can be simply crossed out. It is necessary to find a way to obtain the complement of an arbitrary number X to qn without using subtraction: C = A - B = A + (-B) = A + (-B) + qn - qn = A + (qn -1- B) - qn + 1 Expression qn - 1 - B determines the number B obtained by replacing each digit of the number B with its complement to the digit q –1. So, = = 999. The reverse code B is called the reverse code of the number B; q n -1 is the constant for the formation of the reverse code


It is easy to obtain an additional code from the reverse code: B + B = q n -1 q n - B = B + 1 Additional code of the reverse code The additional code is obtained by adding one to the least significant bit of the reverse code. Therefore, the complement of binary numbers can be found bypassing the subtraction operation. In the reverse code, as in the forward one, there is a negative and positive zero. Only in's two's complement code has a single representation. For a given length of the bit grid, the complement code represents one more negative numbers than positive ones. We agree to denote the direct, reverse and additional codes of the number A through [A pk], [A ok], [A dk].


Example. Find the forward, reverse and additional codes of numbers A = 34 and B = [A pk] =, [A ok] =, [A dk] = [V pk] =, [V ok] =, [V dk] = Algorithm for obtaining complementary code of a negative number. 1.The modulus of a number is represented by direct code in k binary digits. 2. Invert the values ​​of all bits: replace all zeros with ones, and ones with zeros (thus, the k-bit inverse code of the original number is obtained); 3. To the received reverse code, interpreted as a k-bit non-negative binary number, add one.


Examples. 1. Given a negative integer decimal number M = -20. Represent a machine code number on a 16-bit grid in binary and hexadecimal notations. M = -20 = 2 = 2 = 2 = 16 = FFEC


2. An integer is given in the form of a hexadecimal binary machine code. Determine the decimal value of this number: K a = FFD4 The first digit of F, therefore, the number is negative and is stored in the computer in the form of additional machine code. FFD4 16 = [dk] [ok] - reverse code of the number PC = [pc] - forward binary code numbers Then decimal number a = = - (32 + 8 + 4) = -44 - decimal number


Method 2: through the hexadecimal number system K a = FFD4


Actions on machine codes of integers Given: decimal numbers A = 34 and B = 30 Find: A + B, A - B, B - A in binary machine codes in an 8-bit grid. = [A ok] = [A dk] = [-A pk] = [-A ok] = [-A dk] = [-B pk] = [-V ok] = [-V dk] = [V pk ] = [V ok] = [V dk] =


[A + B] DK = = A + B = 64 [A - B] DK = = A - B = 4 [B - A] DK = =


Actions on machine codes of numbers with a fixed point (in hexadecimal notation) Given: decimal numbers A = 34 and B = 30 Find: A + B, A - B, B - A in hexadecimal machine codes in a 16-bit grid ... 1) A = 34 = 22 16 V = 30 = 1E 16 pc = PC = 001E 16 KA + KB = E = A + B = = 64 2) PC = 801E 16 DC = E 16 = FFE2 16 KA + KB = FFE2 = A - B = = 4




In modern computers, the machine form of a number does not store the order itself, but its biased value - a characteristic of the number. This is done in order not to preserve the order sign and, therefore, to facilitate operations over the orders; increase the range of represented numbers ... Sign of the mantissa characteristic mantissa The normalized mantissa always has an integer bit 0 and, therefore, this 0 is not stored in the computer's memory, but only implied. This useful technical solution allows you to increase the number of digits and, therefore, the accuracy of the calculations.


Examples Represent real numbers as machine codes of floating point numbers in a 32-bit grid at 16 s / s: a) A = 32008.5 b) B =, 5 c) C = 15 d) D = Let's find the normalized mantissa and characteristics of these numbers: a ) A = 32008.5 = 7D08.8 16 = 0.7D m A = 0.7D088p xA = 4 + 40 = 44 16 = Sign- 0 Characteristic Fractional part of the mantissa Normalized mantissa Characteristic KA = = = 43FA> 0 0">


B) B =, 5 = -7D08.8 16 = - 0.7D m B = -0.7D088p xB = 4 + 40 = 44 16 = Sign - 1 Characteristic Fractional part of the mantissa Normalized mantissa Characteristic K B = = = C3FA


0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40 "title =" (! LANG: c) C = 15 = F, E 16 mc = 0 , FE 16 p xA = 40 + 1 = 41 16 Sign- 0 Characteristic- 1000001 Fractional part- 1111 1110 0000 0000 0000 0000 mantissa KC = 0.1000001.1111 1110 0000 0000 0000 0000 2 = = 41FE0000 16> 0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40" class="link_thumb"> 28 !} c) C = 15 = F, E 16 mc = 0, FE 16 p xA = 40 + 1 = 41 16 Sign - 0 Characteristic Fractional part of the mantissa KC = = = 41FE> c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40 16 Sign- 1 Characteristic Fractional part of the mantissa KD = = C 0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40 "> 0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40 16 Sign- 1 Characteristic- 1000000 Fractional part- 1001 0000 0000 0000 0000 0000 mantissa KD = 1.1000000.1001 0000 0000 0000 0000 0000 2 = C0900000 16 0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40 "title =" (! LANG: c) C = 15 = F, E 16 mc = 0, FE 16 p xA = 40 + 1 = 41 16 Sign- 0 Characteristic- 1000001 Fractional part- 1111 1110 0000 0000 0000 0000 mantissa KC = 0.1000001.1111 1110 0000 0000 0000 0000 2 = = 41FE0000 16> 0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40"> title="c) C = 15 = F, E 16 mc = 0, FE 16 p xA = 40 + 1 = 41 16 Sign- 0 Characteristic- 1000001 Fractional part- 1111 1110 0000 0000 0000 0000 mantissa KC = 0.1000001.1111 1110 0000 0000 0000 0000 2 = = 41FE0000 16> 0 14 16 c) D = - = - 0.9 16 m B = 0.9 16 p xB = 40 + 0 = 40">!}


Actions on numbers represented in exponential form 1. Numbers in exponential form are stored in memory in direct code with normalized mantissas. 2. The addition of codes is performed by adding the mantissa only for the same orders (characteristics) of the terms. The highest order is chosen for the common one. 3. Algorithms for the operation of algebraic addition after equalizing the characteristics depend on the signs of the terms. 4. Results in straight code are normalized.


Examples Perform the addition operation of machine codes of numbers A and B with floating point in a 32-bit grid. As a response, write down the result code (in the 2nd and 16th s / s) and the corresponding decimal number 1) KA = 43.F34000K B = C1.A13000 a) m A = 00.F34m B = 00.A13 P Ax = 43P Bx = 41 => P = 2 => m B = 00.00A13 - PC _ A13 FF.FF5ED b) m A + m B = 00.F34 FF.FF5ED 100.F29ED> 0 => m A + B = 00.F29ED P = 2 => m B = 00.00A13 - PC _100.00000 00.00A13 FF.FF5ED b) m A + m B = 00.F34 FF.FF5ED 100.F29ED> 0 => m A + B = 00.F29ED " >


P A + B = 3A + B = 0.F29ED = F29, ED 16 = / 16 + 13/256 = / 256 K A + B = = = 43.F29ED0