Analysis on the problems of code, inverse code and complement in Java _java

Source: Internet
Author: User
1. Definition of original code, counter code and complement

1. Original code

The highest bit is the symbol bit (0 is the positive, 1 represents the 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: 00000111
-7 of the original code: 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 against the original code.
For the sake of simplicity, we use 1 bytes to represent an integer:
+7 of the Counter code is: 00000111
-7 of the code is: 11111000

3. Complement

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

The complement of a negative number is known, converted to decimal, and steps:
1, first to you take counter;
2, convert it to decimal number;
3, plus minus, minus 1.
For example:
11111010, the highest bit is 1, is negative, first to you get the reverse 00000101, converted to decimal number 5, plus minus 5, minus 1 to 6.

2. Frequently Asked Questions

Why is the negative number when I a=232 int to the byte type???

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.