title: How does 1 left shift by 31 (1 << 31) work to get maximum int value? Here are my thoughts and some explanations I found online
body: <p>I'm fairly new to bit manipulation and I'm trying to figure out how (1 &lt;&lt; 31) - 1 works.</p>
  
  <p>First I know that 1 &lt;&lt; 31 is </p>
  
  <pre><code>1000000000000000000000000000
  </code></pre>
  
  <p>and I know it's actually complement of minimum int value, but when I tried to figure out (1 &lt;&lt; 31) - 1, I found an explanation states that, it's just </p>
  
  <pre><code>10000000000000000000000000000000 - 1 = 01111111111111111111111111111111
  </code></pre>
  
  <p>I was almost tempted to believe it since it's really straightforward. But is this what really happening? If it's not, why it happens to be right?</p>
  
  <p>My original thought was that, the real process should be: the two's complement of -1 is</p>
  
  <pre><code>11111111111111111111111111111111
  </code></pre>
  
  <p>then (1 &lt;&lt; 31) - 1 =</p>
  
  <pre><code>(1)01111111111111111111111111111111
  </code></pre>
  
  <p>the leftmost 1 is abandoned, then we have maximum value of int.</p>
  
  <p>I'm really confused about which one is right.</p>