title: Reverse 32bit integer
body: <p>I'm trying to solve an exercie in <a href="https://leetcode.com/problems/reverse-integer/#/description" rel="noreferrer">leetcode.com</a> which deals with <code>signed 32bit integers</code>.</p>
  
  <p>The task is: </p>
  
  <p>Return the inverse of a signed 32bit integer and return 0 if it overflows the 32bit signed integer's range.</p>
  
  <p>In <a href="https://en.wikipedia.org/wiki/32-bit" rel="noreferrer">Wikipedia</a>:</p>
  
  <blockquote>
    <p>A 32-bit register can store 32 different values. The range of integer
    values that can be stored in 32 bits depends on the integer
    representation used. With the two most common representations, the
    range is 0 through 4,294,967,295 (2^32 − 1) for representation as an
    (unsigned) binary number, and −2,147,483,648 (−2^31) through
    2,147,483,647 (2^31 − 1) for representation as two's complement.</p>
  </blockquote>
  
  <p>So, if what i understood is correct i should test between the intervals <code>0 to (2^31)-1</code> and <code>(-2^31) to 0</code> otherwise, return <code>0</code>.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def reverse_int(nums):
      a = str(nums)
  
      if 0 &lt; nums &lt;= (1 &lt;&lt; 31)-1:
          return int(a[::-1])
  
      elif (-1 &lt;&lt; 31) &lt;= nums &lt; 0:
          return -(int(a[:-len(a):-1]))
      else:
          return 0
  </code></pre>
  
  <p>Here is my problem: 
  When i test my code on the website with:</p>
  
  <pre><code>nums = 1534236469 # Fail
  nums = 1463847412 # Success
  nums = 9000000    # Success
  </code></pre>
  
  <p>Why my current code fails with <code>1534236469</code> ? isn't <code>1534236469</code> in the range of <code>32 bit signed integers</code> ? What i'm missing ? </p>