Java Algorithms-Symbols ~

Source: Internet
Author: User

~ Take counter

The non-operator is denoted by the symbol "~", and its Operation law is as follows:

If the bit is 0, the result is 1, if the bit is 1, the result is 0

Let's look at a simple example.

 Public class data15{publicstaticvoid  main (string[] args) {int a=2; System.out.println ("a non-result is:" + (~a));}}

        System.out.println (~);        System.out.println (+);        System.out.println (~-63);        System.out.println (~-23);

Results

-4-66222

You can see the pattern.

When the inverse is calculated 0, and the program considers that 0 is a positive number, so in the calculation of inversion must first add 1 in accordance with the normal understanding of the logic to reverse

If the -63+1 is 62

3+1 to 4

Java Algorithms-Symbols ~

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.