Representing numbers on a computer. Representation of numbers in a computer Representation of real numbers in a computer


The maximum value of a non-negative integer is achieved when all cells contain ones. For an n-bit representation it will be equal to

non-negative integers. The minimum number corresponds to the eight zeros stored in the eight bits of the memory cell and is equal to zero. The maximum number corresponds to eight units and is equal to

A = 1 × 2 7 + 1 × 2 6 + 1 × 2 5 + 1 × 2 4 + 1 × 2 3 + 1 × 2 2 + 1 × 2 1 + 1 × 2 0 = 1 × 2 8 - 1 = 255 10 .

Range of change non-negative integers numbers: from 0 to 255.

For storage signed integers two memory cells (16 bits) are allocated, and the most significant (left) bit is allocated to the sign of the number (if the number is positive, then 0 is written to the sign bit, if the number is negative - 1).

The representation of positive numbers in a computer using sign-magnitude format is called direct code numbers. For example, the number 2002 10 = 11111010010 2 would be represented in 16-bit format as follows:

0 0 0 0 0 1 1 1 1 1 0 1 0 0 1 0

The maximum positive number (allowing for the allocation of one digit per sign) for signed integers in n-bit representation is:

Used to represent negative numbers additional code. Additional code allows you to replace the arithmetic operation of subtraction with an addition operation, which significantly simplifies the work of the processor and increases its performance.

The complement code of a negative number A stored in n cells is 2 n - |A|.

Two's complement represents the addition of the modulus of a negative number A to 0, since in n-bit computer arithmetic:

2 n - |A| + |A| = 0,

since in computer n-bit arithmetic 2 n = 0. Indeed, the binary representation of such a number consists of one one and n zeros, and only n low-order digits, that is, n zeros, can fit into an n-bit cell.

To obtain the complementary code of a negative number, you can use a fairly simple algorithm:

1. Write the module of the number in direct code in n binary digits.

2. Get return code numbers, for this value, invert all bits (replace all ones with zeros and replace all zeros with ones).

3. Add one to the resulting reverse code.

Let's write the additional code of the negative number -2002 for the 16-bit computer representation:


When an n-bit representation of a negative number A in two's complement code is used, the most significant bit is allocated to store the sign of the number (one). The remaining digits are written as positive numbers.

For a number to be positive, the following condition must be true:

|A| £ 2 n-1 .

Therefore, the maximum value of the modulus of the number A in the m-digit representation is equal to:

Then the minimum negative number is:

Let's define the range of numbers that can be stored in RAM in the format long signed integers(four memory cells are allocated for storing such numbers - 32 bits).

The maximum positive integer (taking into account the allocation of one digit per sign) is equal to:

A = 2 31 - 1 = 2 147 483 647 10.

The minimum negative integer is:

A = -2 31 = - 2 147 483 648 10.

Advantages of representing numbers in format with fixed point are the simplicity and clarity of the representation of numbers, as well as the simplicity of the algorithms for implementing arithmetic operations.

The disadvantage of representing numbers in format with fixed point is a small range of representation of quantities, insufficient for solving mathematical, physical, economic and other problems in which both very small and very large numbers are used.

Representation of numbers in floating point format. Real numbers are stored and processed in a computer in the format floating point. In this case, the position of the decimal point in the number may change.

Number format floating point is based on exponential notation, in which any number can be represented. So the number A can be represented as:

A = m × q n 2.3

where m is the mantissa of the number;
q - base of the number system;
n - number order.

For uniform presentation of numbers floating point a normalized form is used in which the mantissa meets the condition:

1/n £ |m|

This means that the mantissa must be a proper fraction and have a non-zero digit after the decimal point.

Let's convert the decimal number 555.55, written in natural form, into exponential form with a normalized mantissa:

555.55 = 0.55555 × 10 3.

Here the normalized mantissa is: m = 0.55555, order: n = 3.

A number in floating point format takes up 4 ( common precision number) or 8 bytes ( double precision number). When writing a floating point number, bits are allocated to store the mantissa sign, exponent sign, exponent and mantissa.

The range of numbers is determined by the number of bits allocated to store the order of the number, and the precision (the number of significant digits) is determined by the number of bits allocated to store the mantissa.

Let's determine the maximum number and its accuracy for the format ordinary precision numbers, if 8 bits are allocated to store the order and its sign, and 24 bits are allocated to store the mantissa and its sign:

0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
sign and order sign and mantissa

The maximum value of the order of the number will be 1111111 2 = 127 10, and therefore the maximum value of the number will be:

2 127 = 1.7014118346046923173168730371588 × 10 38.

The maximum value of a positive mantissa is:

2 23 - 1 » 2 23 = 2 (10 × 2.3) » 1000 2.3 = 10 (3 × 2.3) » 10 7.

Thus the maximum value ordinary precision numbers taking into account the possible accuracy of calculations will be 1.701411 × 10 38 (the number of significant digits of a decimal number in this case is limited to 7 digits).

Tasks

1.26. Fill out the table by writing negative decimal numbers in forward, reverse and complement codes in 16-bit notation:

1.27. Define view range signed integers(2 bytes of memory are allocated) in fixed point format.

1.28. Determine the maximum number and its precision for the format double precision numbers, if 11 bits are allocated to store the order and its sign, and 53 bits are allocated to store the mantissa and its sign.

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.

Anyone who has ever thought in life about becoming an “IT specialist” or a system administrator, and simply throwing in their lot with knowledge of how numbers are represented is absolutely necessary. After all, this is what low-level programming languages ​​such as Assembler are based on. Therefore, today we will look at the representation of numbers in a computer and their placement in memory cells.

Notation

If you're reading this article, you probably already know this, but it's worth repeating. All data on a personal computer is stored in binary. This means that any number must be represented in the appropriate form, that is, consisting of zeros and ones.

To convert the decimal numbers familiar to us to a form understandable by a computer, you need to use the algorithm described below. There are also specialized calculators.

So, in order to convert a number to the binary number system, we need to take the value we have chosen and divide it by 2. After this, we will get the result and the remainder (0 or 1). We divide the result again by 2 and remember the remainder. This procedure must be repeated until the end result is also 0 or 1. Then we write down the final value and remainders in the reverse order as we received them.

This is exactly how numbers are represented in a computer. Any number is written in binary form and then occupies a memory cell.

Memory

As you should already know, the smallest unit of information is 1 bit. As we have already found out, numbers are represented in a computer in binary format. Thus, each bit of memory will be occupied by one value - 1 or 0.

Cells are used for storage. Each such unit contains up to 8 bits of information. Therefore, we can conclude that the minimum value in each memory segment can be 1 byte or be an eight-digit binary number.

Whole

Finally, we come to the direct placement of data on the computer. As already mentioned, the processor first converts information into binary format, and only then places it in memory.

We will start with the simplest option, which is the representation of integers in a computer. PC memory allocates a ridiculously small number of cells for this process - only one. Thus, a maximum of one slot can contain values ​​from 0 to 11111111. Let's convert the maximum number into the notation form we are familiar with.
X = 1 × 2 7 + 1 × 2 6 + 1 × 2 5 + 1 × 2 4 + 1 × 2 3 + 1 × 2 2 + 1 × 2 1 + 1 × 2 0 = 1 × 2 8 - 1 = 255 .

Now we see that one memory cell can contain a value from 0 to 255. However, this applies exclusively to non-negative integers. If the computer needs to write a negative value, everything will work a little differently.

Negative numbers

Now let's look at how numbers are represented in a computer if they are negative. To accommodate a value that is less than zero, two memory cells, or 16 bits of information, are allocated. In this case, 15 goes under the number itself, and the first (leftmost) bit goes under the corresponding sign.

If the number is negative, then “1” is written, if positive, then “0”. To make it easier to remember, we can draw the following analogy: if there is a sign, then we put 1, if it is not there, then nothing (0).

The remaining 15 bits of information are allocated to the number. Similar to the previous case, they can accommodate a maximum of fifteen units. It is worth noting that the recording of negative and positive numbers is significantly different from each other.

In order to place a value greater than or equal to zero in 2 memory cells, the so-called direct code is used. This operation is performed in the same way as described, and the maximum A = 32766, if used. I would immediately like to note that in this case “0” refers to positive ones.

Examples

Representing integers in computer memory is not such a difficult task. Although it gets a little more complicated if we are talking about a negative value. To write a number that is less than zero, two's complement code is used.

To obtain it, the machine performs a number of auxiliary operations.

  1. First, the modulus of a negative number is written in binary notation. That is, the computer remembers a similar, but positive value.
  2. Each bit of memory is then inverted. To do this, all ones are replaced by zeros and vice versa.
  3. Add "1" to the result. This will be the additional code.

Let's give a clear example. Let us have a number X = - 131. First we get its modulus |X|= 131. Then we convert it to the binary system and write it in 16 cells. We get X = 0000000010000011. After inversion, X = 1111111101111100. We add “1” to it and get the return code X=1111111101111101. To write to a 16-bit memory cell, the minimum number is X = - (2 15) = - 32767.

Long integers

As you can see, representing real numbers in a computer is not that difficult. However, the considered range may not be sufficient for most operations. Therefore, in order to accommodate large numbers, the computer allocates 4 cells, or 32 bits, from memory.

The recording process is absolutely no different from the one presented above. So we'll just give the range of numbers that can be stored in this type.

X max =2,147,483,647.

X min = - 2 147 483 648.

In most cases, these values ​​are sufficient to record and perform operations with data.

Representing real numbers in a computer has its advantages and disadvantages. On the one hand, this technique makes it easier to perform operations between integer values, which significantly speeds up the processor. On the other hand, this range is not enough to solve most problems in economics, physics, arithmetic and other sciences. Therefore, now we will consider another technique for super-magnitudes.

floating point

This is the last thing you need to know about representing numbers in a computer. Since when writing fractions there is a problem of determining the position of the decimal point in them, scientific notation is used to place such digits in the computer.

Any number can be represented in the following form X = m * p n. Where m is the mantissa of the number, p is the base of the number system and n is the exponent of the number.

To standardize the recording of floating point numbers, the following condition is used, according to which the modulus of the mantissa must be greater than or equal to 1/n and less than 1.

Let us be given the number 666.66. Let's put it in exponential form. It turns out X = 0.66666 * 10 3. P = 10 and n = 3.

Floating point values ​​are typically allocated 4 or 8 bytes (32 or 64 bits). In the first case it is called a regular precision number, and in the second case it is called a double precision number.

Of the 4 bytes allocated for storing digits, 1 (8 bits) is allocated for data about the order and its sign, and 3 bytes (24 bits) are used to store the mantissa and its sign according to the same principles as for integer values. Knowing this, we can carry out simple calculations.

Maximum value n = 1111111 2 = 127 10. Based on it, we can get the maximum size of a number that can be stored in computer memory. X=2 127 . Now we can calculate the maximum possible mantissa. It will be equal to 2 23 - 1 ≥ 2 23 = 2 (10 × 2.3) ≥ 1000 2.3 = 10 (3 × 2.3) ≥ 10 7. As a result, we received an approximate value.

If we now combine both calculations, we get a value that can be written without loss into 4 bytes of memory. It will be equal to X = 1.701411 * 10 38. The remaining numbers were discarded, since this is the accuracy that this recording method allows.

Double precision

Since all the calculations were outlined and explained in the previous paragraph, here we will tell everything very briefly. For double precision numbers, there are usually 11 bits for the exponent and its sign, as well as 53 bits for the mantissa.

P = 1111111111 2 = 1023 10.

M = 2 52 -1 = 2 (10*5.2) = 1000 5.2 = 10 15.6. We round up and get the maximum number X = 2 1023 accurate to the nearest “m”.

We hope that the information we have provided about the representation of integers and real numbers in a computer will be useful to you in your studies and will be at least a little clearer than what is usually written in textbooks.

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 representation of real numbers, which is most beneficial for a computer, is 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):

| 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

A computer's RAM consists of cells, each of which is a 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, pixel sizes of graphic images, 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. The minimum number corresponds to n zeros stored in n bits of memory 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 you are studying.

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 the electronic appendix 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 a 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 in 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.







2024 gtavrl.ru.