The original concept of a binary code, anti-code and complement

This article describes the original code, anti-code and complement the concept, followed by introduction of several positive and negative conversion of the original code, anti-code and complement.

Machine number and the true value

Machine number

A number of binary representation. Wherein the binary bit represents the most negative, 1 for negative, 0 is a positive number. such as

5 (decimal) -> 00000101 (binary)

5 (decimal) -> 10,000,101 (binary)

True value

"+" Or "-" sign to indicate the size plus the absolute value of the value, the value represented by this form. The following example, + 5, -5.

5 (decimal) -> 00000101 (binary) -> + 5 + 000 = 0101

5 (decimal) -> 10000101 (binary) -> -0000101 = -5

To summarize, with the true value is the value of the sign, with the machine number 0 or 1 to indicate the sign of the value.

The concept of the original code, anti-code and complement

Let me talk about the conclusion:

  1. Positive original code, the inverted, complementary codes are the same;
  2. Negative original code: the most significant bit is 1, the remaining bits of the absolute value of the true value;
  3. Inverted negative: on the basis of the original code, change the sign bit, the remaining bits of bitwise;
  4. Negative complement: on the basis of the original code, change the sign bit, the remaining bits inverted, and finally add 1; that is added on the basis of the inverted one.

Original code

Original code: The first symbol representing the remaining bits represent value. for example

+ 12-> 0000 1100 (original code)

-12-> 1000 1100 (original code)

Is in the range corresponding to [1111 1111,0111 1111]the range [-127,127]

Inverted

Positive original code, the inverted, complementary codes are the same;

Inverted negative: on the basis of the original code, change the sign bit, the remaining bits of bitwise. for example:

+ 12-> 0000 1100 (original code) -> 0000 1100 (inverted)

-12-> 1000 1100 (original code) -> 11110011 (inverted)

Complement

Positive original code, the inverted, complementary codes are the same;

Negative complement: for example 12,

  1. -12 original code: 10001100
  2. MSB unchanged, and the remaining bit is inverted: 11,110,011
  3. Was added to obtain a complement: 11110100

Here if you want to turn negative complement the original code, the same method of operation;

  1. -12 Complement: 11,110,100
  2. MSB unchanged, and the remaining bit is inverted: 10,001,011
  3. Was added to give a primitive: 10001100

About complement the range Why is [-128 to 127] problem?

The question I did not get to know, you can look at the second reference links, think about.

Reference links

https://www.cnblogs.com/red-code/p/6520462.html

https://wenku.baidu.com/view/4d9cfe8b7cd184254a353515.html

Guess you like

Origin www.cnblogs.com/benjieqiang/p/11331047.html