Asumming a=1
1+(-1) =0
but with 4 bit binary ,using 2's complement
0001+1111=10000 ~ 0000
Isn't signed integer overflow undefined behavior ?
Do we depend on undefined behavior for such trivial result or I am missing something .
from wikipedia: If the left two carry bits (the ones on the far left of the top row in these examples) are both 1s or both 0s, the result is valid; if the left two carry bits are "1 0" or "0 1", a sign overflow has occurred.
000...01
to111...11
you get000...00
. – lurker11111 111 (carry)
– Mooing Duck