title: Sum of Two Integers without using "+" operator in python
body: <p>Need some help understanding python solutions of leetcode 371. "Sum of Two Integers". I found <a href="https://discuss.leetcode.com/topic/49900/python-solution/2" rel="noreferrer">https://discuss.leetcode.com/topic/49900/python-solution/2</a> is the most voted python solution, but I am having problem understand it.</p>
  
  <ul>
  <li>How to understand the usage of "% MASK" and why "MASK = 0x100000000"?</li>
  <li>How to understand "~((a % MIN_INT) ^ MAX_INT)"?</li>
  <li>When sum beyond MAX_INT, the functions yells negative value (for example getSum(2147483647,2) = -2147483647), isn't that incorrect? </li>
  </ul>
  
  <hr>
  
  <pre><code>class Solution(object):
  
      def getSum(self, a, b):
          """
          :type a: int
          :type b: int
          :rtype: int
          """
          MAX_INT = 0x7FFFFFFF
          MIN_INT = 0x80000000
          MASK = 0x100000000
          while b:
              a, b = (a ^ b) % MASK, ((a &amp; b) &lt;&lt; 1) % MASK
          return a if a &lt;= MAX_INT else ~((a % MIN_INT) ^ MAX_INT)
  </code></pre>