encoding of numbers

Signed numbers have the following encodings:

**Original code: **The normal binary representation of a number, the highest bit represents the symbol, and the source code of the value 0 has two forms

+0 0 000 0000

-0 1 000 0000

Inverse code:

The inverse code of a positive number is the original code, and the inverse code of a negative number is based on the original code. Except for the sign bit, the other bits are inverted bit by bit. There are also two forms of the one's complement of the value 0:

+0 (0 000 0000)

-0  (1 111 1111)

Complement code: the complement code of positive numbers is the original code, and the complement code of negative numbers is based on the original code. Except for the sign, the other bits are reversed bit by bit, and the last bit is +1. If there is a carry, a carry is generated. So the 0's complement of the value has only one form:

+0=-0= 0 000 0000

**Code shift:** The order code used for floating-point number operations, regardless of positive or negative numbers, is the inversion of the first bit (sign bit) of the complement of the original code to get the code shift.

When the word length of the machine is n, the signed value range represented by various code values ​​is different in the representation of 0. The original code and the inverse code are divided into +0 and -0, and the complement code has only one 0, so one more can be represented:

Comprehension: use special value if word length 2

00 , 01 , 10 , 11 only have 4 numbers

For example: If the machine word length is 8, please give 45 and -45 complement of original code and code shift.

convert to binary

+45 = 0001 1101

-45 = 1001 1101

+45          -45

Original code: 0010 1101 1010 1101

Inverse code: 0010 1101 1101 0010

Complement: 0010 1101 1101 0011

Shift code: 1010 1101 0101 0011

Guess you like

Origin blog.csdn.net/flysh05/article/details/124015724