Principles of computer composition (2)--carry counting system, BCD code, signed and unsigned numbers, floating point numbers

Table of contents

1. Carry counting system:

 2. BCD code:

1. Code 8421:

2. Two other code systems: (understand)

 3. Representation and operation of unsigned integers:

1. Unsigned number representation:

​Edit 2. Addition and subtraction of unsigned numbers:

 4. Operations on signed integers:

1. Original code:

 2. Inverse code and complement code:

​edit

3. Complement code calculation:

 1. Addition of complement code:

 2. Subtraction of complement code:

 4. Code shift:

5. Parity check code:

6. Fixed-point integer and fixed-point decimal representation range:

5. Floating point numbers: 

 1. Representation of floating-point numbers:​Edit​Edit

 2. Normalization of floating point numbers:

​Edit 3, IEEE 754 standard:

1. Code shift:

2. IEEE754 standard:

 3. IEEE754 special representation range:


1. Carry counting system:

1. Base : the number of symbols used by each digit, the base of the r-ary number is r.

2. True value : the number with a plus or minus sign that we often say. Example: -1, 12

3. Machine number : the number that digitizes the positive and negative signs, that is, the number stored inside the computer. (The first bit of the binary bit represents the symbol)

The value at each position of the binary system

Representation of each base:

 Convert decimal to binary : 75.3 as an example :

Integer part: write from bottom to top

 Fractional part: written from top to bottom


 2. BCD code:

Use four binary digits to represent a decimal number.

1. Code 8421:

The four-digit binary number can represent up to 16 numbers, but the decimal number is only 0-9, so there will be 6 redundant fields, that is, no decimal number is defined in 1010-1111.

Realize the addition of 8421 codes in the computer:

1. If the result is not within 0000-1001, then add 0 to the front to get the number obtained by adding 0 to the result + 6 to make up the number of digits.

2. If the result is within the defined range of 0000-1001, it can be directly calculated.

2. Two other code systems: (understand)


 3. Representation and operation of unsigned integers:

Overall summary:

1. Unsigned number representation:

1. The word length of the general-purpose register of the computer determines the upper limit of the unsigned number of digits of the computer, and the maximum n-bit machine represents 2^n -1

2. Unsigned numbers use all the digits to represent the number without a sign bit.

3. The largest number is all 1s, and the smallest number is all 0s.

2. Addition and subtraction of unsigned numbers:

Addition : direct bitwise addition.

Subtraction : Invert the subtrahend bit by bit, add 1 at the end, and add the resulting number to the minuend

 


 4. Operations on signed integers:

Overall summary:

1. Original code:

The original code cannot be used for the calculation of two numbers, because the sign bit cannot participate in the operation. Therefore, it is necessary to use the complement code to calculate the truth value.

 2. Inverse code and complement code:

  • The original code, inverse code and complement code of positive numbers are the same.
  • The negative code of the negative number is reversed bit by bit while the basic sign bit of the original code remains unchanged, 0 becomes 1, and 1 becomes 0.
  • The complement of the negative number is based on the inverse code, and the sign bit remains unchanged and 1 is added at the end

A quick way to convert the original code of a negative number to its complement:

Find the first 1 from right to left, and invert all the numbers between the first bit on the left and the sign bit . The sign bit is not negated.

3. Complement code calculation:

The sign bit also participates in the operation, if there is an overflow, only the bits of the operation are taken.

Example: The result of adding 4-bit complement numbers 1100 and 0100 is 10000, but since the number is four bits, the final result is 0000.

 1. Addition of complement code:

 2. Subtraction of complement code:

First convert the subtrahend to its opposite, i.e. AB = A+(-B).

Two's complement conversion:

Conventional method : Invert all bits, +1 at the end. It is all bits, and the sign bit must also be inverted.

Shortcut method: find the first 1 from right to left, and all the bits to the left of it are bitwise inverted, including the sign bit .

In the above 19. 0001 0011, the first 1 from right to left is in the first place, so all the numbers on the left are reversed, and the numbers on the right remain unchanged, that is, the opposite number of its complement.  1110 110 1

 4. Code shift:

Invert the sign bit of the complement code to get the frame shift: the frame shift can only represent integers .

5. Parity check code:

 1. Ensure that the number of 1s in the transmitted data is odd or even. The number of odd checks is guaranteed to be odd, and the number of even checks is guaranteed to be 0.

2. Inspection principle: Exclusive OR operation of information bits is performed on the received data . If the result is 0, the transmission is correct , if it is 1, the transmission error .

3. The parity check can only ensure that there are errors in odd-numbered positions during the transmission process , and cannot detect errors in even-numbered positions.

4. The parity check can only detect errors but not correct them .

6. Fixed-point integer and fixed-point decimal representation range:

There is only one +0 and no -0 in the complement code, and -0 represents the smallest negative number . Eight-bit two-complement number 1 000 0000 represents -128

        For 8-bit binary numbers, the range of complement code is -128~+127, and the representation of original code and inverse code is -127~+127. So for -128, the complement code cannot be used in 8-bit binary code. Inverse code means, because the minimum of inverse code and original code is -127 for eight bits.


5. Floating point numbers: 

 The introduction of floating-point numbers is mainly to represent larger numbers. Floating-point numbers are scientific notation similar to decimal numbers.

 1. Representation of floating point numbers:

 2. Normalization of floating point numbers:

3. IEEE 754 standard:

1. Code shift:

Frameshift = true value + offset value . This offset value is considered to be defined. In the previous calculation, the offset value is 2^n, but in the IEEE754 standard, the offset value is 2^n -1

In the calculation, the sign bit of the complement code is still reversed to obtain the frame shift, and then the result of the frame shift is -1.

2. IEEE754 standard:

One digit character, eight-digit order code (code-shift representation), 23-digit value digit (original code representation)

Because the mantissa is represented by the original code, according to the standardization of floating-point numbers, whether it is a positive number or a negative number, the first digit after the decimal point must be 1, so we have this 1 by default, but it does not save it, so the value of the mantissa written in the figure below is 23 bit but actually 24 bits because the default 1 is not stored.

The -127 and -128 of the exponent code are not used to represent numbers, so the minimum exponent code is -126

 Convert floating point numbers to IEEE754 standard cases:

1. Convert the floating point number to the standard form -1.1*2^-1 The original code of the negative number must be 1.1****

2. Determining the order symbol 1

3. Remove the highest bit 1 to determine the true value. 1000......

4. Determine the frame shift of the order code: the order code is -1, so the complement code is 1111 1111, and the code shift is 0111 1110

5. Match the data according to the specified number of digits.

 Convert the IEEE754 standard to a true value:

Calculate the true value of the exponent code = frame shift - offset (calculated as in decimal)

 3. IEEE754 special representation range:

1. Standard representation:

 2. Special value means:

Guess you like

Origin blog.csdn.net/weixin_60414376/article/details/126852561