The number in Java is a test in the complement notation

Source: Internet
Author: User

First, basic introduction (about the following five definitions from http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html#!comments, Sheyambo master sharing)

What is a machine number: A binary representation of a number in a computer, called the number of machines. The number of machines is signed, in the computer with a number of the highest bit of the symbol, positive is 0, negative number is 1. For example, in decimal +3, the computer word length is 8 bits, the conversion to binary is 00000011. If it is-3, it is 10000011.

What is truth: Because the first bit is the sign bit, the form value of the machine number is not equal to the true value. For example, the above signed number 10000011, its highest bit 1 is negative, its true value is-3 instead of the form value 131 (10000011 is converted to decimal equals 131). So, for the sake of differentiation, the true value of the number of machines with the sign bit is called the truth of the machine number.

What is the original code: the original code is the absolute value of the symbol bit plus the truth, that is, with the first representation of the symbol, the remaining bits represent values. [+1] original = 0000 0001;[-1] Original = 1000 0001.

What is anti-code: The inverse 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] inverse.

What is the complement: the complement of a positive number is itself; the complement of a negative number is on the basis of its original code, the sign bit is unchanged, the rest of you take the reverse, the last +1. (That is, on the basis of the anti-code +1)

Second, inspection

The following code is available:

 1  package   demo;  2  public  class   Bit { 3   static  void   main (string[] args) { 4  int  a=-11  5  System.out.println (a>>1 6  }  8  9 } 

The results of the operation are as follows:

In this program, we use the right shift operation to test the representation of numbers in our java.

A: If the original code is indicated. The number of machines in the 11 is expressed as [10001011], the right shift is represented as [11000101], the decimal is-69, and the positive solution-6 is not the same. So it's not in the original code.

B: If you use a counter-code representation. -11 of the machine number is expressed as [11110100] reverse, after the right shift is expressed as [11111010] reverse, converted to the original code of [10000101], the decimal is 5, and positive solution 6 is not the same. So it's not an anti-code representation.

C: If you use the complement to express. -11 of the machine number is expressed as [11110101] complement, right after the shift is expressed as [11111010] complement, converted to the complement of [111111001], and then converted to the original code of [100000110], the decimal is 6, and positive solution-61. So the number in Java is expressed in the original code.

In summary, the number in Java is expressed in the complement.

The number in Java is a test in the complement notation

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.