3 ms·
And those additional instructions are there only because C modulo is defined to have the same sign as the dividend (so that e.g. -5 % 2 == -1 instead of 1). Had
by Joker_vD 3y ago
And those additional instructions are there only because C modulo is defined to have the same sign as the dividend (so that e.g. -5 % 2 == -1 instead of 1). Had it been defined as being always positive, &1 would have been sufficient in all cases (that would also have the effect of making integer division round to negative infinity instead of zero which too can be implemented simply by >>1, for both signed and unsigned numbers).
- teo_zero 3y agoThank you, today I've learned something new. So the easiest answer to the original question (whether a number is even or odd) likely involves &1, not %2. Note taken.