The prompt forbids arithmetic addition and subtraction but permits bitwise operators on fixed-width signed integers.
Keep true
At every loop boundary, first plus second modulo 2^32 equals the original sum; each pass moves unresolved carries left until second becomes zero.
Reuse it
Separate a binary operation into local output and deferred carry state; the same decomposition underlies half/full adders, bit-mask arithmetic, and fixed-width overflow reasoning.
Read it this way: The loop starts with first=0111 and second=0101. Because second is nonzero, another carry-resolution pass is required. Step through the frames to watch the state change. The last frame shows the answer or the stopping condition.
Pattern: XOR gives sum bits and AND gives carry bits.
Simple idea: XOR adds without carrying. AND finds positions that need a carry. Shift the
carry left and repeat until no carry remains. The mask keeps Python within 32 bits.
def get_sum(first: int, second: int) -> int: mask = 0xFFFFFFFF while second: first, second = (first ^ second) & mask, ((first & second) << 1) & mask return first if first < 0x80000000 else ~(first ^ mask)