Answer:
Whether we add or subtract 1, the least-significant bit changes.
The next higher bit changes (toggles) iff
- the lowest bit is 1 and we are adding, or
- the lowest bit is 0 and we are subtracting.
The next higher bit changes if all lower bits change AND [as above]
(the lowest bit is 1 and we are adding) or
(the lowest bit is 0 and we are subtracting).
Actually, it might be easier to draw this with an adder:
The idea is to add 1 if 'sub' is 0, and
add 7 (which is the same as subtracting 1, in three bits) if 'sub' is 1.
[exam]
[CSC 258 additional problems]
[main course page]