In computer technology, real numbers (as opposed to integers) are numbers that have a fractional part.

When writing them Instead of a comma, it is customary to write a period. So, for example, the number 5 is an integer, and the numbers 5.1 and 5.0 are real.

For the convenience of displaying numbers that take values ​​from a fairly wide range (that is, both very small and very large), the form of writing numbers with base order of the number system. For example, the decimal number 1.25 can be represented in this form as follows:

1.25*10 0 = 0.125*10 1 = 0.0125*10 2 = ... ,
or like this:
12.5*10 -1 = 125.0*10 -2 = 1250.0*10 -3 = ... .

If the “floating” point is located in the mantissa before the first significant digit, then with a fixed number of digits allocated for the mantissa, the maximum number of significant digits of the number is recorded, that is, the maximum accuracy of the number’s representation in the machine. Therefore:

This is the most advantageous representation for a computer. real numbers called normalized.

The mantissa and the order of a q-ary number are usually written in the system with the base q, and the base itself is written in the decimal system.

Examples of normalized representation:

Decimal system Binary system

753.15 = 0.75315*10 3 ; -101.01 = -0.10101*2 11 (order 11 2 = 3 10)

0.000034 = -0.34*10 -4 ; -0.000011 = 0.11*2 -100 (order -100 2 = -410)

Real numbers are written differently in different types of computers. In this case, the computer usually gives the programmer the opportunity to choose from several number formats the most suitable for a particular task - using four, six, eight or ten bytes.

As an example, here are the characteristics of the real number formats used by IBM-compatible personal computers:

Real number formats Size in bytes Approximate range of absolute values Number of significant decimal digits
Single 4 10 -45 ... 10 38 7 or 8
Real 6 10 -39 ... 10 38 11 or 12
Double 8 10 -324 ... 10 308 15 or 16
Advanced 10 10 -4932 ... 10 4932 19 or 20

From this table it can be seen that the form of representation of floating point numbers allows you to write numbers with high precision and from a very wide range.

When storing floating point numbers, they are allocated digits for mantissa, exponent, number sign and exponent sign:

Let us show with examples how some numbers are written in a normalized form in a four-byte format with seven bits to record the order.

1. Number 6.25 10 = 110.01 2 = 0.11001

  • 2 11:

2. Number -0.125 10 = -0.0012 = -0.1*2 -10 (negative order is written in two's complement):

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

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

Table 4

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

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

Table 5

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

Table 6

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

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

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


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

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

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

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

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

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

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

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

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

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

for binary -

for octal -

for hexadecimal -

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

where P is the order of number,

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

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

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

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

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

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

1) the orders of numbers on which the operations are performed are aligned arithmetic operations(the order of a number with a smaller modulus increases to the order of a number with a larger modulo, while the mantissa decreases by the same number of times);

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

3) the result obtained is normalized.

Practical part

If we could look into the contents of computer memory, we would see the following:

This figure reflects Rule #1: Data (and programs) in computer memory are stored in binary form, i.e. in the form of chains of zeros and ones.

Rule #2:representation of data in a computer discretely.

What is discreteness?

Closest answer: "Separate"

Note: A discrete set consists of elements separated from each other. For example, sand is discrete because it is made up of individual grains of sand. But water or oil is continuous (within the framework of our sensations, since we still cannot sense individual molecules)

For example, an image is constructed as a collection of points, i.e. discretely.

Rule #3:the set of quantities representable in memory is limited and finite.

Representing numbers on a computer.

Integers in the computer. (Fixed point format)

Any computing device (computer, calculator) can only work with a limited set of integers. Look at the calculator display, it contains 10 characters. The largest positive number that can be placed on the scoreboard:

9

9

9

9

9

9

9

9

9

The largest negative number in absolute value:

9

9

9

9

9

9

9

9

9

The situation is similar in the computer.

For example, if a memory cell of 16 bits is allocated for an integer, then the largest positive number will be like this:

0

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

In the decimal number system it is equal to:

2 15 -1=32767

Here the first bit plays the role of the sign of the number. Zero is a sign of a positive number. The largest absolute negative number is -32768.

How to get its internal representation:

1) convert the number 32768 to the binary number system, it is equal to
1000000000000000 - received direct code.

2) invert this binary code, i.e. replace zeros with ones, and ones with zeros - we got return code.

0111111111111111

3) Add one to this binary number, the result is:

1

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

A one in the first bit denotes a minus sign.

(don't think that the resulting code is "minus zero". This code represents the number -32768.)

These are the rules for machine representation of integers. This internal representation of a number is called additional code.

If N bits are allocated for an integer in the computer memory, then the range of integer values ​​is: [-2 N-1 -1, 2 N -1]

We looked at the format for representing signed integers, i.e. positive and negative. There are times when you only need to work with positive integers. In this case, the format for representing unsigned integers is used.

In this format, the smallest number is zero, and the largest number for a 16-bit cell is:

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

In decimal notation this is 2 16 - 1 = 65535, twice the absolute value of signed notation.

Integers in the computer. (Floating point format)

The largest number may vary from calculator to calculator. The simplest calculator has 999999999. If you add another unit to it, the calculator will display an error message. And on a “smarter” calculator, adding one will lead to the following result:

1

e

+

0

9

This entry on the scoreboard is understood as follows: 1 x10 9.

This number format is called floating point format.

1

e

+

0

9

mantissa

number order

On a computer, numbers can be represented in both fixed point and floating point formats.

Real numbers in mathematical calculations have no restrictions on the range and precision of number representation. However, in computers, numbers are stored in registers and memory locations with a limited number of digits. That's why accuracy representation real numbers, imaginable in a car, is finite and the range is limited.

When writing real numbers in programs, it is customary to use a dot instead of the usual comma. Any real number can be represented in the form of numbers with the radix order of the number system.

Example 4.4. The decimal number 1.756 in the form of writing numbers with the radix order of the number system can be represented as follows:

1.756 . 10 0 = 0.1756 . 10 1 = 0.01756 . 10 2 = ...

17.56 . 10 -1 = 175.6 . 10 -2 = 1756.0 . 10 -3 = ... .

Floating point representation called number representation N in a number system with a base q as :

N = m* . q p ,

Where m - a multiplier containing all the digits of the number (mantissa), p - an integer called order.

If the “floating” point is located in the mantissa before the first significant digit, then with a fixed number of digits allocated for the mantissa, the maximum number of significant digits of the number is recorded, that is, the maximum accuracy of the number’s representation in the machine.

If in the mantissa the first digit after the dot (comma) is different from zero, then such a number is called normalized .

Mantissa and order q It is customary to write an -ary number in the radix system q , and the base itself is in the decimal system.

Example 4.5. Here are examples of a normalized representation of a number in the decimal system:

2178.01 =0.217801 * 10 4

0.0045 =0.45 * 10 -2

Examples in binary:

10110.01= 0.1011001 * 2 101 (order 101 2 = 5 10)

Modern computers support several international standard formats for storing real floating-point numbers, varying in precision, but they all have the same structure. A real number is stored in three parts: the sign of the mantissa, the shifted order and the mantissa:

Characteristic n-bit normalized number is calculated as follows: if the order is allocated k digits, then an offset equal to (2 k -1 -1) is added to the true value of the order represented in the two's complement code.

Thus, an order taking values ​​in the range -128 to +127 is converted into a biased order in the range 0 to 255. The biased order is stored as an unsigned number, which simplifies the comparison, addition and subtraction operations of orders, and also simplifies the comparison operation the normalized numbers themselves.

The number of digits allocated to the order affects the range from the smallest non-zero number to the largest number representable in the machine given the format. Obviously, the more digits allocated to the mantissa, the higher the accuracy of the number representation. Due to the fact that for normalized real numbers the most significant bit of the mantissa is always 1, this most significant bit is not stored in memory.

Any binary integer containing at most m digits, can be converted into real format without distortion.

Table 4.3. Standard formats for representing real numbers

Example 4.6. Representation of normalized numbers in a single format.

Let's illustrate how the number 37.16 10 will be stored. When converting to a binary number, an exact translation of 100101,(00101000111101011100) does not result - the fractional part enclosed in brackets is repeated in the period.

We convert the number into normalized form: 0.100101(00101000111101011100) * 2 110

Let's represent a real number in 32-bit format:

1. The sign of the number is “+”, so we enter 0 in the sign bit (31);

2. To set the order, 8 bits are allocated; to the true value of the order presented in the complementary code, we add the offset (2 7 -1) = 127. Since the order is positive, the direct order code coincides with the additional order, let’s calculate the shifted order: 00000110 + 01111111=10000101

We enter the resulting shifted order.

3. We enter the mantissa, while removing the most significant digit of the mantissa (it is always equal to 1);

shifted order

mantissa

IN in this example we were able to transfer only 24 bits, the rest were lost with a loss of precision in representing the number.

| Planning lessons for the academic year (FSES) | § 1.2. Representing numbers in a computer

Lessons 6 - 7
§ 1.2. Representing numbers in a computer

Keywords:

Discharge
unsigned integer representation
signed integer representation
representation of real numbers

1.2.1. Integer representation

The computer's RAM consists of cells, each of which represents physical system, consisting of a certain 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 - a digit of a binary number. That is why each cell element is called a bit or digit (Fig. 1.2).

Rice. 1.2. Memory cell

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

Unsigned representation is used for objects such as cell addresses, various counters (for example, the number of characters in text), as well as numbers indicating date and time, sizes graphic images in pixels, etc.

The maximum value of a non-negative integer is achieved when all bits of the cell contain ones. For n-bit representation it will be equal to 2 n -1. 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 pad the resulting result on the left with zeros to standard digit capacity.

Example 1. The number 53 10 = 110101 2 in eight-digit representation has the form:

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

When represented with a sign, the most significant (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 0 is placed in the sign bit, if the number is negative - 1. This representation of numbers is called a direct code.

In computers, direct codes are used to store positive numbers in storage 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 being studied.

To perform operations on negative numbers, additional code is used to replace the subtraction operation with addition. You can find out the algorithm for generating an additional code using the information module “Additional Code” located 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 exponential form:

Where:

m - mantissa of the number;

p - number order.

For example, the number 472 LLC LLC can be represented as follows: 4.72 10 8, 47.2 10 7, 472.0 10 6, etc.

You might have come across the exponential form of writing numbers when performing calculations using a calculator, when you received entries of the following form as an answer: 4.72E+8.

Here, the sign “E” denotes the base of the decimal number system and is read as “multiply by ten to the power.”

From the example above, you can see that the position of the decimal point in a number can change.

For consistency, the mantissa is usually written as a proper fraction with a non-zero digit after the decimal point. In this case, the number 472 LLC LLC will be represented as 0.472 10 9.

A real number can occupy 32 or 64 bits in computer memory. In this case, bits are allocated to store the mantissa sign, order sign, order and mantissa.

Example:

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

The maximum value of the number order for the example above 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 representations of real numbers is important for solving scientific and engineering problems. At the same time, it should be understood that algorithms for processing such numbers are more labor-intensive compared to algorithms for processing integers.

THE MOST IMPORTANT

To represent integers on a computer, 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 the binary number system and the resulting result should be padded on the left with zeros to standard capacity.

When represented with a sign, the most significant digit 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 numbers in complementary code.

When storing real numbers in a computer, bits are allocated to store the sign of the order of the number, the order itself, the sign of the mantissa and mantissa. In this case, any number is written like this:

Where:

m - mantissa of the number;
q - base of the number system;
p - number order.

Questions and tasks

1. Read the presentation materials for the paragraph contained in electronic application to the textbook. Use these materials when preparing answers to questions and completing assignments.

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

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

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

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

a) 01001100;
b) 00010101.

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

7. Write the following numbers in natural form:

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

8. Write the number 2010.0102 10 as five different ways in exponential form.

9. Write the following numbers in exponential form with a normalized mantissa - a proper fraction that has a non-zero digit after the decimal point:

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

10. Draw a diagram connecting the basic concepts discussed in this paragraph.