Original code complement inverse code

Source: Internet
Author: User

1. Original code

The highest bit is used as the sign bit (0 for positive, 1 for negative), and the remainder represents the absolute value of the value itself (in binary notation).
For the sake of simplicity, we use 1 bytes to represent an integer.
+7 The original code is: 00000111
-7 of the original code is: 10000111

2. Anti-code

If a number is positive, then its inverse code is the same as the original code; If a number is negative, the sign bit is 1, and the rest of you are reverse the original code.
For the sake of simplicity, we use 1 bytes to represent an integer:
+7 The anti-code is: 00000111
-7 of the anti-code is: 11111000

3. Complement

Complement: If a number is positive, then its original code, anti-code, and the same complement; If a number is negative, the sign bit is 1, and the rest of you are reversed on the original code, then the whole number is added 1. For the sake of simplicity, we use 1 bytes to represent an integer:
The +7 complement is: 00000111
-7 of the complement is: 11111001

If you know the complement of a negative number, convert it to decimal, step:
1, first of all to take the opposite;
2, convert it to a decimal number;
3, plus minus, minus 1.
For example:
11111010, the highest bit is 1, is negative, first for you to take the reverse 00000101, converted to a decimal number of 5, plus minus 5, and then reduced by 1-6.

Original code complement inverse code

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.