Representing numbers in computer memory

A specific feature is the representation of numbers in the computer's memory, where they must be located in the smallest addressable memory cells - bytes, each of which can contain an arbitrary code of eight binary digits. In turn, numbers can be whole exact, fractional exact, rational, irrational, fractional approximate, can be positive and negative. In addition, "dwarfs" (the mass of the atom), or "giants" (the mass of the Earth). Therefore, the representation of numbers in the computer's memory is how to write a number in one or more bytes. By the address of the number, the address of the first byte should be considered.

A specific feature is the representation of numbers in the computer's memory, where they must be located in the smallest addressable memory cells

To represent numbers in computer memory, computer creators divided sets of numbers into types, each with its own way of representation. The representation of positive integers from 0 to 255 in the computer's memory can be directly in the binary system. Such numbers will occupy one byte.

For negative numbers, the sign of a number can be encoded by a separate high-order bit; zero is interpreted as a plus, one as a minus. Integers in the range from -127 to +127 can then be encoded with a single byte. This representation of integers in the memory of the computer is called a direct code. The situation with negative numbers is somewhat simplified if we use the so-called additional code. In the supplementary code positive numbers coincide with positive numbers in the direct code, negative numbers are obtained as a result of subtraction from 100000000 of the corresponding positive number.

In the two-byte memory cells of the computer there will be a representation of numbers from 0 to 65536 and from -32768 to 32767 in binary (hexadecimal) number system.

In mathematics, real numbers are finite or infinite fractions, the accuracy of which is not limited. But the representation of such numbers in the computer memory is limited by the number of bits in the sequence of bytes. Therefore, infinite or very long numbers are truncated to a certain length, and their representation in the computer's memory becomes approximate.

Very small and very large real numbers can be represented as floating-point numbers.

X = m*qp,

where m is the mantissa of a number; q - base of the number system; p is an integer called the order.

Consider the representation of a real number in the computer's memory. The first bit is used to encode the mantissa sign. The next bit group encodes the order of the number, and the remaining bits encode the absolute value of the mantissa. The lengths of order and mantissa are fixed. The more bits are allocated to the recording of the mantissa, the higher the accuracy of the representation of the number. The more digits occupy the order, the wider the range from the smallest nonzero number to the largest number represented in the computer for a given format.

The order of the number can be either positive or negative. To reflect this in binary form, the magnitude of the order is represented as a sum of the true order and constant equal to the absolute value of the maximum negative absolute order, called displacement.

The real numbers in the computer's memory, depending on the required accuracy (the number of bits of the mantissa) and the range of values (the number of order bits), occupy from four to ten bytes.

Tools