Integers in the computer (original code, inverse code, complement)

Source: Internet
Author: User

All the information in the system, including the disk files, the user data stored in the program memory in the memory, and the data transmitted on the Internet, are represented by a string of bits. The only way to differentiate between different data objects is when we read the context of these data objects. For example, in a different context, an identical sequence of bytes might represent an integer, floating-point number, string, or machine instruction.

Integers in a computer can be classified as unsigned integers and signed integers in two types. Unsigned integers are not positive or negative, and are stored in the computer in the form of binary truth. Signed integers are relatively complex because they are distinguished by positive and negative numbers.

The number of symbols in a computer has three representations, that is, the original code, the inverse code and the complement. The three representations have both symbolic and numeric digits, their most significant bit being the sign bit, all using 0 for "positive", and 1 for "negative", and the value bits, three methods of representation are different.

Original code (SIGN-MAGNITUDE):

The original code is the absolute value of the symbolic bit plus the truth, that is, the first digit represents the symbol, and the remaining bits represent the values. For example, if it is a 8-bit binary:

[+1] original = 0000 0001

[-1] original = 1000 0001

Because the first bit is the sign bit, the range of values for the 8-bit binary number is:

[1111 1111, 0111 1111]

That

[-127, 127]

The original code is the most easily understood and calculated representation of the human brain.

Anti-code (Ones ' complement):

The inverse code of a positive number is itself; the inverse of a negative number is on the basis of its original code, the sign bit is unchanged, and the remaining bits are reversed.

[+1] = [00000001] original = [00000001] Reverse

[-1] = [10000001] original = [11111110] Reverse

Visible if an inverse code represents a negative number, the human brain can not intuitively see its value, usually to convert it to the original code and then calculate.

Complement (s complement)

The complement of a positive number is the original code itself, the complement of the negative is in its original code on the basis of the symbol bit unchanged, the rest of you take the counter, the last +1 (that is, on the basis of the anti-code +1).

[+1] = [00000001] original = [00000001] counter = [00000001] Complement

[-1] = [10000001] original = [11111110] counter = [11111111] Complement

For negative numbers, the complement representation is also the human brain can not intuitively see its value, usually also need to convert to the original code in the calculation of its value.

Why the final use of complement?

In order to simplify the structure and increase the speed of computing, the computer designers transform subtraction, multiplication and division into addition operations. Subtracting a positive number from the algorithm equals adding a negative number, but the computer's identification of the "sign bit" obviously complicates the design of the computer's basic circuit, so people come up with a way to take the symbolic bit into the operation.

The original code and the inverse code have a strange attribute, that is, for the number 0 there are two different encoding methods. Both of these representations put 00. 00 is interpreted as +0, whereas a value of 0 is represented as 10 in the original code. 00, expressed as 11 in the inverse code: 11. Obviously, the 0 plus sign is meaningless, and it affects the target of the symbolic bit participating in the operation. The complement solves this problem, and 0 has only one expression in the complement, that is, all the bits are 0.

With the complement, the symbolic and numerical fields can be processed uniformly, and the addition and subtraction can be processed uniformly. In addition, the complement and the original code are converted to each other, the operation process is the same, no need for additional hardware circuit.

Integers in the computer (original code, inverse code, complement)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.