Java Fundamentals (long-term updates)

Source: Internet
Author: User

Want to record the basic knowledge of Java, if you encounter a miscellaneous problem, also add to here, no longer another new blog

1. Shift operation (<<, >>)

 Public Static void Main (string[] args) {        int a = 8;         // 8<<3--8 * (2 of 3 times)        System.out.println ("8<<3----->" + (8<<3));         // 8>>3--8/(2 of 3 times)        System.out.println ("8>>3----->" + (8>>3));            }
8<<3----->648>>3----->1

The shift operation is the fastest in the computer.

Take 11 as an example

11 binary corresponding is 1011

11<<3 Move right 3-bit to get 1011--and decimal 88 "11* (2 of 3)"

11>>3 move left 3-bit to get 1--and decimal 1 "11/(2 3)"

Put on the code to verify it.

 Public Static void Main (string[] args) {         int a = one;                  System.out.println (Integer.tobinarystring (a));                  System.out.println (Integer.tobinarystring (a<<3) + "decimal:" + (a<<3));                  System.out.println (Integer.tobinarystring (a>>3) + "decimal:" + (a>>3));            }
101,110,110,000 binary: 8,810 binary: 1

  

2. Bitwise non-operator (~)

 Public Static void Main (string[] args) {        int A =-9;         int b = 9;         int c = 0;         // ~a--(-a-1)        System.out.println ("~a---->" + (~a));        System.out.println ("~b---->" + (~b));        System.out.println ("~c---->" + (~c));                }
~a---->8~b---->-10~c---->-1

Java Fundamentals (long-term updates)

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.