Why should the computer use the complement?

Source: Internet
Author: User

The computer uses the complement to represent a negative integer . The positive integer is represented by the source code. What is the complement? In fact, the source code is the opposite number of source code, they add up to 0. calculates the complement of a negative integer:

The rule is the source code you take the counter, and then add 1 to get.

For example, if we use 8 digits to represent a signed integer, then decimal 1 is represented by a binary:

00000001
The result of this number-plus 1 is:

11111111

So, the 1 complement is 11111111.

You may have questions, exactly what is the complement, why-1 of the complement is not-1 of the source code to add 1 it.

This is because:-1 of the complement is 1 of the complement notation. So the computer uses the opposite number of 1 (that is, the complement of 1) to represent-1.


to compute the decimal number of a binary signed number

Since the number of symbols in the computer has a complement to represent a negative integer, how do we compute the decimal number according to the given binary number?

See Example:

Suppose given a number:

10000100

Look at the sign bit is 1, is negative, so this number is represented by the complement. First compute the source code.

The results of the counter plus 1 are:

01111100 (binary) = 124 (decimal)

So the decimal number of the original binary number is-124.


calculating the binary complement representation of negative integers

To continue with that example, if we get a decimal-124, then what is his binary complement?

In fact, his complement is 124 of the binary number of the result of the complement.

The binary number of 124 is: 01111100

Take counter: 10000011

Plus 1:10.0001 million

So--124 of the binary complement is said to be 10000100


Why do I use the complement to represent a negative integer

The reason is simple, if you use the complement to represent a negative integer, then the ALU in the operation between integers, there is no need to distinguish between the symbols, all bits will participate in the operation, in the above example, the symbol bit are involved in the operation.

For example, to perform the operation of 2-1, we can use the (-1) to calculate.

The binary number of 2 is: 00000010

The binary number of 1 is: 00000001-->-1 of the binary complement is: 11111111

So the hydrate (-1):

  00000010
+ 11111111
----------------
  00000001

The result is 1.

Let's look at a negative result.

The result of 1-2 is calculated with 1+ (-2).

The binary number of 2 is: 00000010, so the binary number of 2 is: 11111101+1=11111110

The 1+ (-2) calculation process is:

  00000001
+ 11111110
---------------
  11111111

What is the decimal number of this result?

First of all, it is a negative number, indicating the result using the complement, will you take 1 after the result is 00000001=1 (decimal), and then add his symbol, is-1,

So the result of 1+ (-2) is-1.

Using the complement computation does simplify the ALU design difficulty. So the computer uses the complement to represent the negative integer ....


I should have seen it clearly.












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.