Order code

Information science terminology
Collection
zero Useful+1
zero
stay machine One in Floating point number It is necessary to give an index. This index is expressed in the form of an integer. This integer is called order code, which indicates that decimal point stay data Position in.
Chinese name
Order code
Foreign name
exponent
Representation method
Fixed-point number representation
Field
information science

brief introduction

Announce
edit
Order code: any binary number N can be represented by N=S × 2 ^ P, where S is the mantissa, P is the order code, 2 is the bottom of the order code, P and S are represented by binary numbers, S represents all significant digits of N, and P indicates the position of the decimal point. When the order code is a fixed value, this representation of number is called fixed-point representation, and such number is called“ Number of fixed points ”; When the order code is variable, this representation of number is called floating-point This number is called“ Floating point number ”。

characteristic

Announce
edit
Order code: When representing a floating point number in the machine, it is necessary to give an index. The index is expressed in the form of an integer, which is called the order code.
1. When the order code is a fixed value, this representation of number is called fixed-point representation, and such number is called "fixed-point number"; When the order code is variable, this representation of numbers is called floating point representation, and such numbers are called "floating point numbers".
2. "Shift code" is used to represent the order code of floating point decimal. For positive numbers, the sign bit is "1", and the rest bits remain unchanged, for example, the order code of+1110001 is 11110001; For negative numbers, the sign bit is "0", the rest bits are reversed, and "1" is added at the end. For example, the order code of – 1110001 is 00001111. [1]

Relevant knowledge

Announce
edit
1. Code shift (also called code increase) is the complement of sign bit inversion. Generally, the order code of floating point number is made by subtracting 1 from the exponential code shift. The purpose of the introduction is to ensure that the machine zero of floating point number is all zero.
2. When the order code is expressed by complement code, when the order code is infinitely small and underflow occurs, the order code becomes 0, and the value of this floating point number becomes 1. If the rank code overflows (exceeds the maximum value indicated by the rank code), set the overflow flag; if the rank code overflows (code shifting indicates 00... 0), set the result to machine 0.
3. Using complement codes, symbol bits and numerical fields can be processed uniformly; At the same time, addition and subtraction can also be handled uniformly. In addition, the complementary code and the original code are converted to each other, and the operation process is the same, without additional hardware circuits.
4. The coding scheme of complement is to solve how to represent negative numbers in the machine. Its essence is to use a positive number to represent the negative number corresponding to the positive number. The complement of - 20 refers to how to represent - 20 in the form of complement in the machine.

Fixed-point number representation

Announce
edit
usually Number of fixed points There are two representations, both of which are P=0, and the decimal point is implied. If the numerical part is n digits:
When S is pure integer At this time Number of fixed points It can only represent integers, and the range of N that can be represented is (2n-1) ≥ N ≥ - (2n-1); When S is pure decimal At this time, fixed-point numbers can only represent decimals, and the range of N that can be represented is (1-2-n) ≥ N ≥ - (1-2-n).
The actual values are not necessarily pure integers or pure decimal The scale factor can be selected before the operation, so that all the original data can be converted into pure decimal or pure integer, and then the scale factor can be used to restore the actual value after the operation. [2]

BCD code

Announce
edit

executive summary

Usually, we are used to using Decimal number Represents data, but the computer uses Binary number To represent data, which requires conversion between numeric and decimal. We put every Decimal number The code for converting binary numbers is called BCD code for short. BCD code has Binary number In the form of digital system And has Decimal number Characteristics of. In some cases, the computer can also directly operate on this form of number.
It is a kind of digital compression storage code. A byte has 8 bits, while the number 0 to 9 only needs to use 4 bits at most. If a byte is used to store a number, there will be a certain waste. Especially in the transmission process, people came up with a compression method, namely BCD coding.
BCD code splits 8 bits of a byte into two parts: the upper 4 bits and the lower 4 bits, that is, a byte can store two numbers. So the encoding process of BCD is the process of compressing numbers, which compresses two byte numbers into one byte. On the contrary, decoding is to split a byte number into two numbers and store them separately (most of the processing is byte based). [3]

coding method

8421BCD code
8421BCD code list
This is the most widely used BCD code , is a kind of weighted code. The weights of each bit are 8, 4, 2, 1 (i.e. 23, 22, 21, 20) (from the most significant bit to the least significant bit), so it is called "8421BCD code".
in use 8421BCD code It must be noted that there are only ten valid codes, namely, 0000~1001. 4-bit Binary number The other six codes 1010, 1011, 1100, 1101, 1110 and 1111 of are not valid codes. The 8421BCD code is shown in Table 2-3. This BCD code is actually the "equivalent" of 0~9 Binary number
2421BCD code
2421BCD code is also a kind of weighted code. Its weights from high to low are 2, 4, 2 and 1 (also the reason for its name). It can also use 4-bit binary digits to represent 1-bit Decimal number
Remaining 3 yards
The remaining three yards are also one kind BCD code , but it is an unauthorized code. But because each code corresponds to 8421 BCD code The difference between them is 3, so it is called the remaining 3 codes. It is generally used less, so only a general understanding is needed.
Use BCD code Base When converting, it is required to quickly convert the two forms of decimal system, rather than the meaning of "equal values".
For example, calculate Decimal number BCD code of 2000 and its Binary number
The BCD code of 2000 is to convert the numbers 2, 0, 0, and 0 on each bit into their corresponding BCD codes: 0010, 0000, 0000, and 0000. When they are combined, the BCD code of 2000 is 0010000000000000.
Decimal number 2000 Binary number Yes: 11111010000, they are equal in value.
take Decimal number 86.5 converted to BCD code The final result is: (1000011001001) BCD.
take BCD code 10010111.0100 converted to Decimal number The result is 97.4.
In IBM PC, according to different storage formats in memory, BCD code It can also be divided into:
• Compression type BCD code : Two decimal digits are stored in one byte.
• Non compression BCD code : Only one byte is stored Decimal number
For example: set Decimal number Compression type for 8762 BCD code Means: 100001101100010.

Code shifting

Announce
edit
A code system called code shifting is also commonly used to represent floating point numbers. The order code of the floating point number represents the size of the exponent, which has positive and negative values. To avoid the symbol of the order code, a positive constant (called the offset constant) is added to each order code, so that all the order codes that can be represented are positive integers, and become "offset" order codes, also called "incremental codes". The code shift value is not less than 0, so the order code is always 0, which can be canceled. The actual position of the floating point decimal point is determined by the code shift minus the offset constant.
A real number can be expressed as a pure decimal With a Power Product. For example: - 0.0010011=- 0.10011 × 2 ^ - 10 (10 is also binary here); - 110001101=- 0.110001101 × 2 ^ 1001 (1001 is also binary).
An arbitrary real number, which can be summed by the exponent (integer) and Mantissa For pure decimal )The method of using exponent and mantissa to express real numbers is called floating-point Representation.
Floating point number The length can be 32 bits, 64 bits or even longer Mantissa Two parts. The more order code digits, the larger the range of numbers that can be expressed; The more mantissa, the higher precision of the number represented. Code shifting ”Used to represent floating point type decimal The order code of. about Positive number , the sign bit is "1", and the rest bits remain unchanged, for example, the order code of+1110001 is 11110001; about negative , the sign bit is "0", the rest bits are reversed, and "1" is added at the end. For example, the rank code of – 1110001 is 00001111.
Code shifting And Complement The relation of is that the sign bits are opposite to each other (different signs), for example, when X=+1011, [X] shift=11011, [X] complement=01011; When X=– 1011, [X] shift=00101, [X] complement=10101.
Note: Yes Code shifting The result of the operation needs to be corrected by 2n, that is, the correct result in the form of code shifting is obtained after the sign bit of the result is reversed. Code shifting In the representation, 0 has a specific code - 1000... 00. When 000... 00 appears (representing – 2n), it belongs to floating point underflow.