Quote: "Pardon? There's no "flip over" in your example."
You said
flips over to the start, which I assume means flipping over to the first value (ie. 0). Otherwise, this demonstrates it when the 32nd bit flips:
last = 2147483647 ` 1 before the flip
current = -2147483640 ` 8 after the flip
print current - last
wait key
Quote: "That's a non-issue? "
Well I sure don't see an issue:
last = -40
current = -10
print current - last
wait key
I'm going to pre-empt someone telling me I'm counting backwards, and show what happens when you reach the 32nd bit:
Unsigned: 1 ... 2147483647 ... 2147483648 ... 2147483649 ... 4294967295 ... 0
Signed: 1 ... 2147483647 ... -2147483648 ... -2147483647 ... -1 ... 0
Quote: "The "flip over" referred to is the enormous change in value you get when the counter reaches its maximum possible value and then in the next instant "overflows" to its smallest possible value, so the change has to be negative"
Correct the change is negative. However, it's such a big change that it cannot fit in a 32-bit variable and thus an underflow occurs, yielding a positive value.
If you had have done some testing, you would have found this the case:
last1 = 0
cur1 = 10
last2 = 2147483647
cur2 = 2147483657 ` -2147483639
last3 = 4294967295 ` -1
cur3 = 9
print "Normal: "+str$(cur1 - last1)
print "32-bit flip: "+str$(cur2 - last2)
print "Maximum flip: "+str$(cur3 - last3)
wait key
The
only time a negative value can result is if the difference is higher than (2^31)-1.