yeah, i was thinking of a method that does not involve arithmetic operation, just pure binary operations, it will not overflow:
a=1234;
b=2;
a=a^b;
b=a^b;
a=a^b;
^ is the XOR binary operator
note that:
P XOR P = 0
and that 0 XOR P =P
first step:
a=a XOR b b =b
second step:
a=a XOR b b=a XOR b XOR b = a XOR 0 =a
third step:
a=a XOR b XOR a = b XOR 0 = b b=a;