Displacement operations in Java

Source: Internet
Author: User

The shift operator is the translation of a number on the basis of a binary. the rules for panning direction and filling numbers are divided into three:<< (left), >> (with symbol right), and >>> (unsigned Right shift).

The calculation rules are as follows:

the ① left n is equal to the n-th side multiplied by 2.

② The right shift n is equal to the n-th squared by 2. Here is to take the Shangha, the remainder will not be.

③>>> (unsigned Right shift)

Operation rules:

Press Binary The form moves all numbers to the right by the corresponding number of digits, the low position is shifted out (discarded), and the upper seat is 0. For positive numbers, it is the same as a signed right shift, which is different for negative numbers. Other structures and >> similar.

Example

[Java] view plaincopyprint?
  1. long &NBSP;A&NBSP;=&NBSP; 0x3 ;&NBSP;&NBSP;
  2. long &NBSP;B&NBSP;=&NBSP; 30 ;&NBSP;&NBSP;
  3. long  longleft  =  a << b;  
  4. system.out.println (longLeft);   
  5. system.out.println (0x3 &NBSP;<<&NBSP; 30
  6. system.out.println ("-----"
  7. system.out.println (Math.pow (-2 ,&NBSP; 31
  8. system.out.println (Integer.MIN_ VALUE);   
  9. system.out.println ("-----"
  10. system.out.println (Math.pow (2 ,&NBSP; 31 1
  11. System.out.println (Integer.max_value);
Results

[plain] view plaincopyprint?
  1. 3221225472&NBSP;&NBSP;
  2. -1073741824
  3. -----
  4. -2.147483648E9
  5. -2147483648
  6. -----
  7. 2.147483647E9
  8. 2147483647



Displacement operations in Java

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.