title: What are the exact semantics of Rust's shift operators?
body: <p>I tried to find exact information about how the <code>&lt;&lt;</code> and <code>&gt;&gt;</code> operators work on integers, but I couldn't find a clear answer (<a href="https://doc.rust-lang.org/stable/std/ops/trait.Shr.html" rel="noreferrer">the documentation</a> is not that great in that regard). </p>
  
  <p>There are two parts of the semantics that are not clear to me. First, what bits are "shifted in"?</p>
  
  <ul>
  <li>Zeroes are shifted in from one side (i.e. <code>0b1110_1010u8 &lt;&lt; 4 == 0b1010_0000u8</code>), or </li>
  <li>the bits rotate (i.e. <code>0b1110_1010u8 &lt;&lt; 4 == 0b1010_1110u8</code>), or</li>
  <li>it's unspecified (like overflowing behavior of integers is unspecified), or</li>
  <li>something else.</li>
  </ul>
  
  <p>Additionally, how does shifts work with signed integers? Is the sign bit also involved in the shift or not? Or is this unspecified?</p>