Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Java specification explains the <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.19" rel="noreferrer">shift operators</a> as follows:</p> <blockquote> <p>If the promoted type of the left-hand operand is <code>int</code>, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator <code>&amp;</code> (<a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.22.1" rel="noreferrer">§15.22.1</a>) with the mask value <code>0x1f</code>. The shift distance actually used is therefore always in the range 0 to 31, inclusive.</p> </blockquote> <p>The value of <code>32 &amp; 0x1f</code> is zero.</p> <p>If the left operand is <code>long</code>, then you get an extra bit for the right operand, expanding the upper limit to 63 instead of 31.</p> <hr> <p>In order to have any specific expected value from shifting -1 to the right, you need to specify the underlying binary representation of integers (e.g., two's complement) as well as the number of bits (e.g., 32). Each programming language can define those differently, but in the interest of keeping things simpler for the implementation, they'll usually specify that shifting by more than the number of available bits is not allowed. That's often because the underlying CPU hardware doesn't support it, either. After all, if you want to shift that many bits, the left operand no longer matters since the result will always be the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload