Floating point numbers and their computer representation. Representation of numbers in a computer. Representation of integers and real numbers in computer memory. For positive numbers, direct, inverse and additional codes are the same, i.e. direct code. P

💖 Like it? Share the link with your friends

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

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

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

Change range 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 assigned under 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 computer representation of positive numbers using sign-value format is called direct code numbers. For example, the number 2002 10 = 11111010010 2 would be represented in 16 bits as follows:

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

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

Used to represent negative numbers additional code. The additional code allows you to replace the arithmetic operation of subtraction with the operation of addition, which greatly simplifies the work of the processor and increases its speed.

The additional code of the negative number A stored in n cells is 2 n - |A|.

The complement code is the addition of the module of the negative number A to 0, since in n-bit computer arithmetic:

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

since in computer n-bit arithmetic 2 n \u003d 0. Indeed, the binary notation of such a number consists of one unit and n zeros, and only n lower digits, that is, n zeros, can fit into an n-bit cell.

To get the additional code of a negative number, you can use a fairly simple algorithm:

1. Write the modulus 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 received return code.

Let's write the two's complement code of -2002 for the 16-bit computer representation:


With an n-bit representation of a negative number A in the additional code, the most significant bit is allocated to store the sign of the number (one). The rest of the bits are positive.

For the number to be positive, the condition must be satisfied

|A| £ 2 n-1 .

Therefore, the maximum value of the modulus of the number A in the n-bit representation is:

Then the minimum negative number is:

Define the range of numbers that can be stored in random access memory in the format signed long integers(four memory cells are allocated for storing such numbers - 32 bits).

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

A \u003d 2 31 - 1 \u003d 2 147 483 647 10.

The minimum negative integer is:

A \u003d -2 31 \u003d - 2 147 483 648 10.

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

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

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 comma in the notation of 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 × qn 2.3

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

For uniform representation of numbers floating point the 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 \u003d 0.55555 × 10 3.

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

A floating point number occupies 4 in computer memory ( ordinary 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 digits allocated for storing the order of the number, and the accuracy (the number significant figures) is determined by the number of bits allocated for storing the mantissa.

Determine the maximum number and its precision for the format ordinary precision numbers, if 8 bits are allocated for storing the order and its sign, and 24 bits for storing 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:

2127 = 1.7014118346046923173168730371588 × 1038.

The maximum value of the 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, it 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 in the table by writing negative decimal numbers in direct, reverse and two's complement codes in 16-bit representation:

1.27. Define View Range signed integers(2 bytes of memory allocated) in fixed-point format.

1.28. Determine the maximum number and its precision for a 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.

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

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

Example 4.4. The decimal number 1.756 in the form of numbers with the order of the base 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 = ... .

Representing a floating point number is called a representation of a number N in base number system q as :

N = m* . qp ,

Where m - multiplier containing all digits of the number (mantissa), p is an integer, called the 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 representation of the number in the machine.

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

Mantissa and order q -ary number is usually written in a system with a base q , and the base itself is in the decimal system.

Example 4.5. Here are examples of the 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, which differ in precision, but they all have the same structure. A real number is stored in three parts: mantissa sign, offset exponent, and mantissa:

Characteristic n-bit normalized number is calculated as follows: if the order is allocated k bits, then to the true value of the order presented in the additional code, add an offset equal to (2 k -1 -1).

Thus, an order that takes values ​​in the range from -128 to +127 is converted to a shifted order in the range from 0 to 255. The shifted order is stored as an unsigned number, which simplifies the operations of comparing, adding and subtracting 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 that can be represented on the machine with a given format. Obviously, the more digits are allocated for recording the mantissa, the higher the accuracy of the representation of the number. Due to the fact that the most significant bit of the mantissa is always 1 for normalized real numbers, this most significant bit is not stored in memory.

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

Table 4.3. Standard Formats for Representing Real Numbers

Example 4.6. Representation of normalized numbers in single format.

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

We translate the number into a 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 put 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 additional code, we add the offset (2 7 -1) = 127. Since the order is positive, then the direct code of the order coincides with the additional one, we calculate the shifted order: 00000110 + 01111111=10000101

We enter the resulting shifted order.

3. We enter the mantissa, while removing the high order of the mantissa (it is always equal to 1);

shifted order

mantissa

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

| Lesson planning for the academic year (FSES) | § 1.2. Representation of numbers in a computer

Lessons 6 - 7
§ 1.2. Representation of numbers in a computer

Keywords:

Discharge
unsigned representation of integers
signed integer representation
representation of real numbers

1.2.1. Integer representation

Computer 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 serves to store one of the bits - a digit binary number. That is why each element of the cell is called a bit or bit (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 (for integers, 8, 16, 32, or 64 digits are usually assigned) and the presence or absence of a sign bit. Unsigned representation can only be used for non-negative integers, negative numbers are represented only in signed form.

Unsigned representation is used for 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 is achieved when units are stored in all digits of the cell. For an n-bit representation, it will be 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 binary system calculus and supplement the result obtained on the left with zeros to the standard bit depth.

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

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

When presented with a sign, the most significant (left) digit is assigned to the sign of the number, the remaining digits - to the number itself. If the number is positive, then 0 is placed in the sign bit, if the number is negative - 1. Such a representation of numbers is called a 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/) hosts 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 that allows you to replace the operation of subtraction with addition. You can find out the algorithm for generating an 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 exponential form:

Where:

m is the mantissa of the number;

p is the order of the number.

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.

With the exponential form of writing numbers, you could meet 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 above example, it can be seen that the position of the comma in the notation of a number can change.

For uniformity, 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 sign of the mantissa, the sign of the exponent, the exponent, and the mantissa.

Example:

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

The maximum exponent value for the above example is 1111111 2 = 127 10 , and therefore the maximum number value is:

0,11111111111111111111111 10 1111111

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

A wide range of representation of real numbers is important for solving scientific and engineering problems. At the same time, it should be understood that the algorithms for processing such numbers are more time-consuming compared to the algorithms for processing integers.

THE MOST IMPORTANT

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

To represent an unsigned integer, it should be converted to the binary number system and the result obtained should be supplemented with zeros on the left to the standard bit depth.

When presented with a sign, the most significant digit is assigned to the sign of the number, the remaining digits 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 a direct code, negative ones in an additional one.

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

Where:

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

Questions and tasks

1. Familiarize yourself with the presentation materials for the paragraph contained in the electronic supplement 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 expediency of having special ways of computer representation of integers.

4. Write 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 of the numbers 443 8 , 101010 2 , 256 10 can be stored in 8-bit format?

7. 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.

8. Write down 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 linking the main concepts discussed in this paragraph.

Numeric data is processed in a computer in the binary system. Numbers are stored in computer memory binary code, i.e. 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 is allocated for storing non-negative integers, consisting of eight memory cells (8 bits). Each digit of the 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 like this:

Table 4

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

Unlike the decimal system, in the binary system, in the computer representation of a binary number, there are no symbols denoting 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 bit (leftmost) is used under 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 value in signed number format (assuming one digit is represented as a 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 format is used, which allows you to replace the arithmetic subtraction operation in a computer with an addition operation, which greatly simplifies the structure of the microprocessor and increases its speed.

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


1) write the modulus of the number in a 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 received inverse code.

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

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

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

The computer representation of fixed-point numbers has its advantages and disadvantages. TO benefits include the simplicity of the representation of numbers and algorithms for the implementation of arithmetic operations, the disadvantages are the finite range of representation of numbers, which may not be sufficient 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 format for representing a number, the position of the comma in the record can change. Any real number K in floating point format can be represented as:

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

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

for binary -

for octal -

for hex -

This form of 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 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 floating-point decimal form 15.5 is not used when writing computer programs and entering them into a computer (computer input devices accept only linear data recording). Based on this, the expression (2.7) for representing decimal numbers and entering them into a computer is converted to the form

where P is the order of the 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 put. Thus, the number 15.5 in floating point and linear notation (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 writing is called unnormalized . For an unambiguous representation of floating-point numbers, a normalized form of the 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 has a non-zero after the decimal point, then the number is called normalized. So, the number 15.5 in the 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 the order P = 2, or in the computer representation of the number 0.155Е2 .

Floating point numbers have a fixed format and take up four (32 bits) or eight bytes (64 bits) of computer memory. If the number occupies 32 bits in the computer memory, then this is a normal precision number, if 64 bits, then this is a double precision number. When writing a floating point number, bits are allocated to store the mantissa sign, exponent sign, mantissa, and exponent. The number of digits allocated for the order of the number determines the range of change of numbers, and the number of digits allocated for storing the mantissa determines the accuracy with which the number is specified.

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

1) alignment of the orders of numbers on which arithmetic operations are performed (the order of a smaller number in absolute value increases to a value of the order of a larger number in absolute value, while the mantissa decreases by the same number of times);

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

3) the result is normalized.

Practical part

Subject: Representation of numbers in a computer. Fixed and floating point format. Direct, reverse and additional code.

Repetition: Converting integers to binary number system:

13 10 = A 2 Similarly:

13 10 =1101 2

1345 10 =10101000001 2


Representation of integers in a computer.

All information processed by computers is stored in them in binary form. How is this storage done?

The information entered into the computer and arising in the course of its operation is stored in its memory. Computer memory can be represented as long page, consisting of separate lines. Each such line is called memory cell .

cell - is a part of the computer memory that contains information available for processing by a separate team processor. The minimum addressable memory cell is called a byte - 8 binary digits. The sequence number of a byte is called its address .

cell (8bit = 1byte)

machine word.

A memory cell consists of a certain number of homogeneous elements. Each element is capable of being in one of two states and serves to represent one of the digits of a number. That is why each cell element is called discharge . It is customary to number the digits in a cell from right to left, the rightmost digit has a serial number 0. This is the least significant bit of a memory cell, the most significant bit has a serial number (n-1) in an n-bit memory cell.

The content of any bit can be either 0 or 1.

The contents of a memory cell is called machine word. A memory cell is divided into digits, each of which stores a digit of a number.

For example, the most modern personal computers are 64-bit, that is, a machine word and, accordingly, a memory cell, consists of 64 bits or bits.

Bit - the minimum unit of measurement of information. Each bit can be either 0 or 1. beat also called discharge computer memory cells.

Standard size The smallest memory cell is equal to eight bits, that is, eight binary digits. A set of 8 bits is the basic unit of data representation - a byte.

Byte (from English byte - syllable) - a part of a machine word, consisting of 8 bits, processed in a computer as a whole. On the screen - a memory cell consisting of 8 bits - this is a byte. The least significant digit has a serial number 0, the most significant digit has a serial number 7.

8 bits = 1 byte

Two formats are used to represent numbers in computer memory: fixed point format And floating point format . Fixed-point format represents only whole numbers , in floating point format - real numbers (fractional).

In the vast majority of problems solved with the help of a computer, many actions are reduced to operations on integers. This includes tasks of an economic nature, in the solution of which the data are the number of shares, employees, parts, Vehicle etc. Integers are used to denote dates and times, and to number various objects: array elements, database entries, machine addresses, and so on.

Integers can be represented in a computer with or without a sign (be positive or negative).

Unsigned integers usuallyoccupy one or two bytes of memoryand accept in single-byte format values ​​from 00000000 2 to 11111111 2 , and in double-byte format - from 00000000 00000000 2 to 11111111 11111111 2 .

Signed integers usually occupy one, two or four bytes in computer memory, while the leftmost (highest) bit contains information about the sign of the number. The plus sign is encoded as zero, and the minus sign is encoded as one.

1101 2 10101000001 2

The digit allocated under the sign

(in this case +)

Missing to the whole byte high-order bits are filled with zeros.

IN computer technology Three forms of notation (coding) of signed integers are used:straight code , back code , additional code .

Direct code - this is a representation of a number in the binary number system, while the first digit is assigned to the sign of the number. If the number is positive, then the first digit is 0; if the number is negative, the first digit is one.

In fact, the direct code is used almost exclusively for positive numbers.To write a direct number code, you must:

    Represent a number in binary

    Pad the number entry with zeros to the penultimate high-order digit of an 8-bit or 16-bit cell

    Fill the highest bit with zero or one, depending on the sign of the number.

Example: the number 3 10 in the direct code of the one-byte format will be represented as:


hislo -3 10 in the direct code of a single-byte format it looks like:


Reverse code for a positive number in the binary number system, it is the same as the direct code. For a negative number, all digits of the number are replaced by opposites (1 to 0, 0 to 1)invert, and one is entered in the sign bit.

For negative numbers, the so-called additional code is used. This is due to the convenience of performing operations on numbers by computer technology.

Additional code They are mainly used to represent negative numbers in a computer. Such code makes arithmetic operations more convenient for computing.

In the additional code, as well as direct, the first digit is reserved to represent the sign of the number. The direct and additional codes for positive numbers are the same. Since the direct code is used almost exclusively for representing positive numbers, and the additional one for negative ones, then almost always, if the first bit is 1, then we are dealing with an additional code. (Zero indicates a positive number, and one indicates a negative number).

Algorithm for obtaining an additional code for a negative number:

1. Find the direct code of the number (translate the number into the binary number system unsigned number)

2. Get a return code. Change every zero to one and every one to zero (invert the number)

3. Add 1 to the reverse code

Example: Let's find the additional code of the decimal number - 47 in 16-bit format.

    Let's find the binary representation of the number 47 (direct code).

2. Invert this number (reverse code). 3. Add 1 to the reverse code and get a record of this number in RAM.

Important!

For positive numbers, direct, inverse and additional codes are the same, i.e. direct code. Positive numbers do not need to be inverted for computer representation!

Why is it usedextra code to represent a negative number?

This makes it easier to do math. For example, we have two numbers represented in direct code. One number is positive, the other is negative, and these numbers must be added. However, you can't just put them together. First, the computer must determine what these numbers are. Having found out that one number is negative, he should replace the operation of addition with the operation of subtraction. Then, the machine must determine which number is greater in modulo, in order to figure out the sign of the result and decide what to subtract from what. As a result, it turns out complex algorithm. It's much easier to add numbers if the negative ones are converted to two's complement.

Practical task:

Exercise 1. Write the forward, backward, and two's complement codes of the following decimal numbers using8-bitcell:

64 10, - 120 10

Task 2. Write the direct, inverse and additional codes of the following decimal numbers in a 16-bit grid

57 10 - 117 10 - 200 10



tell friends