Sum of Two Integers without using '+' operator in python 2 or 3
<pre><code>class Solution(object):
    def getSum(self, a, b):
        if (a == 0):
            return b
        if (b == 0):
            return a;
        while(b != 0):
            _a = a ^ b
            _b = (a &amp; b) &lt;&lt; 1
            a = _a
            b = _b
        return a
</code></pre>

<p>But when one of a, b &lt; 0 or both, how the script should be like?</p>

<p>My old highschool program that I found on my usb stick. Yes it's crude but it works.</p>

<pre><code>def s(a,b):
    a = bin(a)[2:]
    b = bin(b)[2:]
    c_in = 0
    value = ''
    if not len(a) == len(b):
        to_fill = abs(len(a) - len(b))

        if len(a) &gt; len(b):
            b = b.zfill(len(a))
        else:
            a = a.zfill(len(b))

    for i,j in zip(reversed(a),reversed(b)):
        i_xor_j = int(i) ^ int(j)
        i_and_j = int(i) and int(j)
        s = int(c_in) ^ int(i_xor_j)
        c_in_and_i_xor_j = int(c_in) and int(i_xor_j)
        c_in = int(i_and_j) or int(c_in_and_i_xor_j)
        value += str(int(s))
    value += str(int(c_in))

    return int(value[::-1],2)

print(s(5,9))
#&gt;&gt; 14
</code></pre>

<p>Or I would have see if I could cheat with <code>sum</code>.</p>

python