title: Arithmetic bit-shift on a signed integer
body: <p>I am trying to figure out how exactly arithmetic bit-shift operators work in C, and how it will affect signed 32-bit integers.</p>
  
  <p>To make things simple, let's say we work within one byte (8 bits):</p>
  
  <pre><code>x = 1101.0101
  MSB[ 1101.0101 ]LSB
  </code></pre>
  
  <p>Reading other posts on Stack Overflow and some websites, I found that:
  <code>&lt;&lt;</code> will shift toward MSB (to the left, in my case), and fill "empty" LSB bits with 0s.</p>
  
  <p>And <code>&gt;&gt;</code> will shift toward LSB (to the right, in my case) and fill "empty" bits with MS bit</p>
  
  <p>So, <code>x = x &lt;&lt; 7</code> will result in moving LSB to MSB, and setting everything to 0s.</p>
  
  <pre><code>1000.0000
  </code></pre>
  
  <p>Now, let's say I would <code>&gt;&gt; 7</code>, last result. This would result in <code>[0000.0010]</code>? Am I right?</p>
  
  <p>Am I right about my assumptions about shift operators?</p>
  
  <p>I just tested on my machine, **</p>
  
  <pre><code>int x = 1;   //000000000......01
  
  x = x &lt;&lt; 31; //100000000......00
  
  x = x &gt;&gt; 31; //111111111......11 (Everything is filled with 1s !!!!!) 
  </code></pre>
  
  <p>Why?</p>